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

被刻印的时光 ゝ 提交于 2019-12-22 06:00:16

问题


so from what i gather, Socket connections are neither serializable or parcelable, but i need to pass a bluetooth connection 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.


回答1:


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();


来源:https://stackoverflow.com/questions/5158758/how-to-pass-a-bluetooth-socket-to-another-activity-using-application-interface

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!