开发者

How to send an intent to an activity and read extras from it?

There's a service which runs always and listens to some events, will push them into a log someday. I would like to display those events in the main actvity when it's running, but how to send the event details to the activity? You don't receive the intent itself, when you send it to the activity with Context.startActivity(), so that you can't re开发者_C百科trive the data with Intent.getXxxExtra().

(The activity would "subscribe" and "unsibscribe" to the events in onStart() and onStop() with an intent sent to the service, so that the events wouldn't open the activity if it's not in foreground)

Or is there any other way to send data (20-30 characters long String) from a service to an intent?


Issue a Broadcast from your Service and implement a private BroadcastReceiver in your activity.


Yes, you can use the Handler class for message passing between your Service and your main Activity.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜