开发者

How to pass a Bluetooth Socket to another Activity using Application interface

开发者 https://www.devze.com 2023-02-14 17:11 出处:网络
so from what i gather, Socket connections are neither serializable or parcelable, but i need to pass a bluetooth con开发者_如何学编程nection to another Activity.i do not want to write a Service as a m

so from what i gather, Socket connections are neither serializable or parcelable, but i need to pass a bluetooth con开发者_如何学编程nection to another Activity. i do not want to write a Service as a middle man, so please don't post this as a solution. i've heard that there is a way to pass these types of Objects using a custom Application interface, but i cannot, for the life of me, find a working example of this. i've seen plenty of documentation that says something to the effect of "this is possible" but nothing showing how to do it.


Define your app class:

class MyApplication extends Application{
    // your fields here
}

Add name attribute to app manifest.

<application android:name=".MyApplication" ../>

Use it in Activity:

MyApplication myapp = (MyApplication) getApplication();
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号