当天更新的更新小部件
问题描述:
我有一个小部件,显示当前日期和其他东西。但是,只有当用户在主要活动中执行操作时,才会更新小部件。当天更新的更新小部件
我将如何着手强制小部件在下次午夜后打开电话时进行更新以反映新的日期?
我知道我可能需要一个AlarmManager,但我不清楚参数。我是否把它放在我的主要活动中,让它调用我的小部件上调用更新的方法?
答
类似的风格,我有一个服务,我想在某个时间运行。当这个服务完成它的工作时,它会更新我的小部件并停止它自己(服务)。这里是我如何在指定的时间启动我的服务的一个片段
Intent mSrvcIntent = new Intent(packageContext, MyService.class);
PendingIntent mSrvcPendingingIntent = PendingIntent.getService(packageContext,0, mSrvcIntent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager mAlarmManager = (AlarmManager)context.getSystemService(android.content.Context.ALARM_SERVICE);
mAlarmManager.set(AlarmManager.RTC_WAKEUP, time to start service, mSrvcPendingingIntent);
我希望这是近得让你能够
答
广告这个解决您的问题以您的清单部件接收
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
<action android:name="android.intent.action.DATE_CHANGED" />...
onReceive()会触发
我需要一个帮助它在我们的应用程序中定义这个报警管理器。 – Satheesh 2014-01-21 04:11:06
http://developer.android.com/reference/android/app/AlarmManager.html – SteelBytes 2014-01-21 05:12:51