android – 如何将数据从服务发送到我的活动?

android – 如何将数据从服务发送到我的活动?,第1张

概述我有两个活动A和B.我需要从A开始服务.服务将执行一些 *** 作.我需要在活动B中使用服务中的一些数据.我该怎么做. 请用示例代码解释一下. 您可以通过StartService方法中的intent发送数据. 这个代码来自我的服务(StartService方法) Intent updater = new Intent();updater.setAction(AppWidgetManager.ACTION 我有两个活动A和B.我需要从A开始服务.服务将执行一些 *** 作.我需要在活动B中使用服务中的一些数据.我该怎么做.
请用示例代码解释一下.解决方法 您可以通过StartService方法中的intent发送数据.

这个代码来自我的服务(StartService方法)

Intent updater = new Intent();updater.setAction(AppWidgetManager.ACTION_APPWidget_UPDATE);updater.putExtra("betHour",pref.getInt("Hr",exampleHour));updater.putExtra("betMin",pref.getInt("Mn",exampleMinute));PendingIntent pen =     PendingIntent.getbroadcast(getApplicationContext(),updater,PendingIntent.FLAG_UPDATE_CURRENT);AlarmManager alarmManager =     (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME,SystemClock.elapsedRealtime() + 1000,60000,pen);
总结

以上是内存溢出为你收集整理的android – 如何将数据从服务发送到我的活动?全部内容,希望文章能够帮你解决android – 如何将数据从服务发送到我的活动?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1127245.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存