简体   繁体   English

如何将数据从服务发送到 Android Studio 中的活动?

[英]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.

相关问题 我如何从后台服务向Android中的活动发送列表 - How can i send a list from Background service to activity in android 如何在一个活动中将图像从ImageView发送到另一个活动中的ImageButton。 Android Studio - How can I send an image from an ImageView in one activity to an ImageButton in another activity. Android Studio 无法将数据从 Activity 发送到 Android Studio 上的片段 - Can not send data from Activity to fragment on Android Studio 如何在 android studio 中使用 bundle 将数据发送到下一个活动 - how can I send the data to the next activity using bundle in android studio 如何将清单发送到Android Studio中的另一个活动 - how can I send a List into another activity in Android Studio 如何将数据从本地服务发送到ANDROID中的活动 - How to send data from local service to activity in ANDROID Android-如何将数据从活动发送到服务? - Android- How to send data from activity to service? 将数据从服务发送到Android活动 - Send Data from Service To Activity Android 如何从 appcompat 活动更改为 Android 工作室中的活动? - How can I change from appcompat activity to Activity in Android studio? Android Studio - 如何将数据从 MainActivity.xml 发送到服务? - Android Studio - How to send data from MainActivity.xml to Service?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM