[英]How can I send data from a Service to an Activity in Android Studio?
I have a service that is started in Activity1.我有一个在 Activity1 中启动的服务。 Activity1 sends a String which is received by Service1.
Activity1 发送一个由 Service1 接收的字符串。 When the recent items are closed and Service1's Notification is clicked I want Service1 to open Activity1 using a String from Service1.
当关闭最近的项目并单击 Service1 的通知时,我希望 Service1 使用来自 Service1 的字符串打开 Activity1。
Your assistance will be greatly appreciated.非常感谢您的协助。
TIA TIA
TheRealMrP真正的先生
Just Refer this只需参考这个
Using Binding/Unbinding of the service使用服务的绑定/解除绑定
https://medium.com/@sahityakumarsuman/android-service-communication-with-activity-2c01e537ab03 https://medium.com/@sahityakumarsuman/android-service-communication-with-activity-2c01e537ab03
OR要么
Using interface trick.使用界面技巧。
You can create a interface, define the listener method inside the activity and call the listener method inside your service.您可以创建一个接口,在活动中定义侦听器方法并在您的服务中调用侦听器方法。
WARNING : It can give you null pointer error, so don't forget to check if the service and the activity are alive while calling.警告:它会给你 null 指针错误,所以不要忘记在调用时检查服务和活动是否存在。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.