English 中文(简体)
机器人将动力从服务发送到活动
原标题:Android send impulse from service to activity

在一项服务中,我准备了一些数据,然后将这些数据储存在一个静态成员变量中,通过广播将一个没有数据的意向发送到主要的UI活动,以使活动知道数据已经编制完毕并随时可以访问。

但既然我每秒需要做10次, 即通过广播发送一个脉冲(完全没有数据)有点过火,

是否有更好的办法做到这一点?

问题回答

您应该< a href=> http:// developmenter.android.com/guide/potics/fundamentals/services.html#CreateBoundServicice' rel=“nofollow'> 将您的 service /code> 添加到您的 Acticality 上, 并使用简单的回调或 Message handler 设施将您的数据发送到周围。 从您所说的话看, 简单的回调可能适合您的需要。





相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...