从另一个类中调用的主要活动方式 [英] Calling main activity method from another class

查看:167
本文介绍了从另一个类中调用的主要活动方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我写这个程序将基本发送的蓝牙消息到另一台设备时,我收到一条短信。要发送的蓝牙消息,我用在这里找到蓝牙样品聊天应用程序:<一href="http://developer.android.com/resources/samples/BluetoothChat/src/com/example/android/BluetoothChat/BluetoothChat.html"相对=nofollow>主源文件。在收到短信方面,我按照这个例子

So I'm writing this app that will basically send a bluetooth message to another device when I receive an SMS. To send the bluetooth message, I use the Bluetooth sample chat app found here: main source file. In terms of getting the SMS, I follow this example.

基本上以收到短信我注册一个BroadcastReceiver。

Basically in order to receive an SMS I register a BroadcastReceiver.

有关蓝牙聊天,有一个私人BluetoothChatService被初始化和设置应用程序启动时。该对象是用在写入通过蓝牙功能。

For the Bluetooth chat, there is a private BluetoothChatService which is initialized and set up when the app starts. That object is used in the function that writes through Bluetooth.

现在的问题是,我也不太清楚如何访问对象或write方法。另外我pretty的肯定,我解释了我树立正确​​的,所以请仔细检查我张贴的链接只是为了确保我已经解释了它的权利。

Now the problem is that I'm not too sure how to access either the object or the write method. Also I'm pretty sure I explained my set up right, so please double check the links I posted just to make sure I've explained it right.

推荐答案

要调用从另一个类中的主要活动方式,你需要引用这项活动在类,或者您需要一个处理程序(回调)。您可以使用去处理程序的主要活动定义,当你想调用一些code,将消息发送给这个处理程序(如蓝牙示例,您提供作品)。

To call a main activity method from another class you need a reference to this activity in that class, or you need a handler (callback). You can either go with the Handler defined in main activity, and when you want to invoke some code, send a message to this handler (like the Bluetooth sample you provide works).

这篇关于从另一个类中调用的主要活动方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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