android - How do I retrieve Intent Extras within a Service started by an AlarmManager schedule? -
android - How do I retrieve Intent Extras within a Service started by an AlarmManager schedule? -
public void oncreate() { super.oncreate(); int idfunc = getapplicationcontext().getsharedpreferences(spref_name,context.mode_private).getint("idfunc", 0); string seckey = getapplicationcontext().getsharedpreferences(spref_name,context.mode_private).getstring("chave", null); intent intent = new intent(getapplicationcontext(), serviceenviaclientes.class); bundle bundle = new bundle(); bundle.putstring("seckey", seckey); bundle.putint("idfunc", idfunc); intent.putextras(bundle); pendingintent pintent = pendingintent.getservice(getapplicationcontext(), 0, intent, 0); alarmmanager alarm = (alarmmanager)getsystemservice(context.alarm_service); alarm.setrepeating(alarmmanager.rtc_wakeup, calendar.getinstance().gettimeinmillis(), 10*60000, pintent); initimageloader(this); }
i'm trying pass extras provided sharedprefereces alarmmanager intent , retrieve within service, instead of access sharedpreferences while service running think demands more memory.
@override public int onstartcommand(intent intent, int flags, int startid) { super.onstartcommand(intent, flags, startid); toast.maketext(this,"task perform in service",toast.length_short).show(); bundle bundle = intent.getextras(); midfunc = bundle.getint("idfunc"); mseckey = bundle.getstring("seckey"); threadjsonbuild td=new threadjsonbuild(); td.start(); log.d(tag, "onstartcommand cycle, idfunc: "+midfunc+" , seckey: "+mseckey); homecoming super.onstartcommand(intent, flags, startid); }
but i'm getting null
on mseckey
, 0
on idfunc
. i'm not sure if it's best option, i'd set sharedpreferences retrieves within service's oncreate()
method, not sure really.
when call
pendingintent pintent = pendingintent.getservice(getapplicationcontext(), 0, intent, 0);
you may getting existing pendingintent
doesn't have extras in it. should use
pendingintent pintent = pendingintent.getservice(getapplicationcontext(), 0, intent, pendingintent.flag_update_current);
instead. ensure extras set in intent
. aware, however, extras replaced in users of pendingintent
.
android android-intent android-service alarmmanager android-pendingintent
Comments
Post a Comment