简体   繁体   English

如何将其他服务(从带有通知的警报开始)发送到MainActivity?

[英]How to send extras from Service (start from alarm with Notification) to MainActivity?

My MainActivity has Alarm . 我的MainActivityAlarm Alarm starts to repeat Service and send data to it from intent.putExtra from pendingIntent . Alarm开始重复Service ,并从数据发送给它intent.putExtrapendingIntent When Service returns true, then it autocanсels itself (by new pendingIntent -> cancel) and sends data to Notification (if the user clicks on it, the app will start with new data from that Notification or the user only starts app -> it will load with new data). Service返回true时,它将自动取消自身(通过新的pendingIntent Intent->取消)并将数据发送到Notification (如果用户单击它,则应用将从该Notification新数据开始,或者用户仅启动app->它会加载新数据)。 I need to send my putExtras from Notification to MainActivity , getExtra in MainActivity , and (if that is possible) commit it automatically. 我需要把我的putExtrasNotificationMainActivitygetExtraMainActivity ,以及(如果可能的话)会自动提交。

If I'm right, i must use startActivityForResult before calling Service , but how can I do this with Alarm ? 如果我是正确的,我必须在调用Service之前使用startActivityForResult ,但是如何使用Alarm来做到这一点?

PS already work all except for that step " Notification.putExtras() -> MainActivity.getExtras() . 除了该步骤“ Notification.putExtras() -> MainActivity.getExtras() ”以外,PS已经可以正常工作。

I think that what you are looking for are Bound Services . 我认为您正在寻找的是绑定服务

A bound service is an implementation of the Service class that allows other applications to bind to it and interact with it. 绑定服务是Service类的一种实现,它允许其他应用程序与其绑定并与其交互。

Take a look at this and let me know if it helped. 看看这个 ,让我知道是否有帮助。 Here they talk about the alternatives to communicate between service and activities: servicecommunication . 他们在这里讨论在服务和活动之间进行通信的替代方案: servicecommunication

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

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