简体   繁体   English

Android:从后台服务开始活动

[英]Android : start activity from background service

I have a background service running all the time after bootup. 启动后,我一直在运行后台服务。 Based on some condition I have to start activity from service and get the response from activity. 根据某些条件,我必须从服务开始活动,并从活动获得响应。 After getting the response I have to do some processing in service. 得到响应后,我必须在服务中进行一些处理。

I google searched and found that I should use notifications. 我在Google上搜索,发现我应该使用通知。 But its not clear how to send the response back from activity to service. 但是尚不清楚如何将响应从活动发送回服务。

Can anyone please help me out. 谁能帮我一下。

Thnaks. 谢谢。

The reason for notifications is that the background service shouldn't just suddenly pop up with some UI demanding input. 发出通知的原因是,后台服务不应只是突然弹出一些要求输入的UI。 I'd suggest you use status bar notifications to signal that you need some input. 我建议您使用状态栏通知来表示您需要一些输入。 The user can then opt in to activate the notification which in turn issues the intent to display the activity. 然后,用户可以选择激活通知,从而发出显示活动的意图。 The activity in turn can use service binding mechanisms to communicate any data back to the service. 该活动又可以使用服务绑定机制将任何数据传递回服务。

In other words: the background service remain as passive as possible and the user is still in charge. 换句话说:后台服务尽可能保持被动状态,并且用户仍然负责。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM