是否有sendToActivity()方法? [英] Is there a sendToActivity() method?

查看:94
本文介绍了是否有sendToActivity()方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个约8活动类,1类应用程序。我希望我的应用程序类能够与所有的活动进行沟通,但就其本身而论。我不想问的应用程序对数据的活动,我希望应用程序发送的活动数据。这里的问题是,根据程序的当前状态,我不能确定哪些活动将被打开。

I have a program with about 8 Activity classes, and 1 Application class. I want my Application class to be able to communicate with every Activity, but on its own terms. I don't want the activity to ask the Application for data, I want the Application to send the Activity data. The problem with this, is that depending on the current state of the program I'm unsure what Activity will be open.

有某种它们可以从应用程序将信息发送到当前活动的方法?

Is there a method of some sort which will send information from the Application to the CURRENT activity?

Application类具有嵌入式蓝牙设备连接,需要接受不同的部分,这取决于活动的用户目前在数据的。我本来它作为一个普通班,这是在我的程序的MainMenu的初始化,并通过处理程序。然而,这似乎是弱电设计传递的处理程序,从活动到活动一次又一次。

The Application class connects with an embedded Bluetooth Device and needs to receive different pieces of data depending on which Activity the user is currently in. I originally had it as a regular class, which was initialized in the MainMenu of my program and passed a Handler. However, it seemed like weak design to pass that Handler from Activity to Activity time and time again.

推荐答案

您可以使用回调方法

每一件事情都有它自己的回调方法,并在注册应用程序类的方法 onResume()。 (它就像一个 onApplicationWantsToDoSomethingWithMeListener()

Every Activity has it's own callback method and registers that method onResume() in the Application Class. (it's like an onApplicationWantsToDoSomethingWithMeListener() ;)

为什么不能在后台服务?而不是应用程序,因为你想要什么听起来像一个服务。更多细节?

or why not a Service in background? instead of the Application, since what you want sounds like a Service. More details?

编辑: 我做了一个类似的应用程序与蓝牙,您应该definetly使用服务为,但您可以用每个应用程序的服务进行通信。假设服务在应用程序<一个调用回调href="http://$c$c.google.com/p/projectneo/source/browse/#svn%2FProjectNEO%2Fbranches%2Fv2%2Fsrc%2Fch%2Fbaws%2Fprojectneo%2FsendService"相对=nofollow>在这里寻找一个实现UF这样的事情

I made a similar application with bluetooth, you should definetly use a Service for that, but you can communicate with your service per Application. Say the Service calls the callback in the Application look here for an implementation uf such a thing

这篇关于是否有sendToActivity()方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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