如何使用应用程序接口,通过蓝牙套接字到另一个活动 [英] How to pass a Bluetooth Socket to another Activity using Application interface

查看:126
本文介绍了如何使用应用程序接口,通过蓝牙套接字到另一个活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以从我收集,套接字连接既不是序列化或parcelable,但我需要通过蓝牙连接到另一个活动。我不想写一个服务作为中间人,所以请不要张贴此作为解决方案。我听说有一种方式来传递这些类型的使用自定义的应用程序接口的对象,但我不能,因为我的生活,发现这是一个工作的例子。我已经看到了大量的文档,上面写着东西的,这是可能的,但没有说明如何做到这一点的影响。

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.

推荐答案

定义您的应用程序类:

class MyApplication extends Application{
    // your fields here
}

添加名称属性来应用清单。

Add name attribute to app manifest.

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

使用它的活动:

MyApplication myapp = (MyApplication) getApplication();

这篇关于如何使用应用程序接口,通过蓝牙套接字到另一个活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆