i know possible duplicate, havent found specific answer this? (there partial answers on how force widget update every second not after...)
i need have widget update once minute.
how make battery&cpu&ram efficient widget purpose? (the data fetched internet , parsed before showing user(a small amount of data , processing done.))
should make service runs on boot if user has widget on screen , have service schedule alarm manager wakes service updates widget?
also pause service if screen locked or off save battery...
that's how did similar. created service (intentservice
if don't need complicated) , register alarm manager.
long interval = intervalminutes * 60 * 1000; long firsttime = calendar.getinstance().gettimeinmillis(); intent = new intent(ctx, alarmservice.class); // use widget id update 1 widget @ time. i.putextra(appwidgetmanager.extra_appwidget_id, id); pendingintent malarmsender = pendingintent.getservice(ctx, id, i, pendingintent.flag_update_current); alarmmanager = (alarmmanager) ctx.getsystemservice(alarm_service); am.setrepeating(alarmmanager.rtc_wakeup, firsttime, interval, malarmsender);
being alarmservice.class service or intentservice.
for boot event, can create broadcastreceiver
, manage android.intent.action.boot_completed
action can register alarm.
you can register event in androidmanifest
:
<receiver android:name=".broadcastreceiverwidget" > <intent-filter> <action android:name="android.intent.action.boot_completed" /> </intent-filter> </receiver>
Comments
Post a Comment