i use alarmmanager start activity via pendingintent.
intent smon = new intent(ctxt, videoactivty.class); final bundle = new bundle(); extra.putstring("extrastring","monday"); smon.putextras(extra); //smon.putextra("extrastring","monday"); smon.setflags(intent.flag_activity_single_top); pendingintent psmon = pendingintent.getactivity(ctxt, 0, smon, 0); calendar calset1 = calendar.getinstance(); calset1.set(calendar.month, c.get(calendar.month)); calset1.set(calendar.year, c.get(calendar.year)); calset1.set(calendar.day_of_week, 2); calset1.set(calendar.hour_of_day, hsmon); calset1.set(calendar.minute, msmon); calset1.set(calendar.second, 0); calset1.set(calendar.millisecond, 0); int delay1=0; if(today.get(calendar.day_of_week)>2)delay1=7 * 24 * 60 * 60 * 1000; if((today.get(calendar.day_of_week)==2)&&(today.get(calendar.hour_of_day)>hsmon))delay1=7 * 24 * 60 * 60 * 1000; if((today.get(calendar.day_of_week)==2)&&(today.get(calendar.hour_of_day)==hsmon)&&(today.get(calendar.minute)>msmon))delay1=7 * 24 * 60 * 60 * 1000; log.e("delay 1",integer.tostring(delay1)); //calset.settimezone(timezone.gettimezone("utc")); mgr.setrepeating(alarmmanager.rtc_wakeup, calset1.gettimeinmillis()+delay1, 7 * 24 * 60 * 60 * 1000, psmon); as can see there in intent: "extrastring".
now, when try tor read started activity:
protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); // final bundle = getintent().getextras(); string message="cazzo"; if (extra != null) { message=extra.getstring("extrastring"); } log.e("intent che รจ partito",message); i nullpointerexception.
thanks help
07-19 13:34:18.336: e/androidruntime(14109): fatal exception: main 07-19 13:34:18.336: e/androidruntime(14109): java.lang.runtimeexception: unable start activity componentinfo{com.example.videdrome/com.example.videdrome.videoactivty}: java.lang.nullpointerexception: println needs message 07-19 13:34:18.336: e/androidruntime(14109): @ android.app.activitythread.performlaunchactivity(activitythread.java:2180) 07-19 13:34:18.336: e/androidruntime(14109): @ android.app.activitythread.handlelaunchactivity(activitythread.java:2230) 07-19 13:34:18.336: e/androidruntime(14109): @ android.app.activitythread.access$600(activitythread.java:141) 07-19 13:34:18.336: e/androidruntime(14109): @ android.app.activitythread$h.handlemessage(activitythread.java:1234) 07-19 13:34:18.336: e/androidruntime(14109): @ android.os.handler.dispatchmessage(handler.java:99) 07-19 13:34:18.336: e/androidruntime(14109): @ android.os.looper.loop(looper.java:137) 07-19 13:34:18.336: e/androidruntime(14109): @ android.app.activitythread.main(activitythread.java:5041) 07-19 13:34:18.336: e/androidruntime(14109): @ java.lang.reflect.method.invokenative(native method) 07-19 13:34:18.336: e/androidruntime(14109): @ java.lang.reflect.method.invoke(method.java:511) 07-19 13:34:18.336: e/androidruntime(14109): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:793) 07-19 13:34:18.336: e/androidruntime(14109): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:560) 07-19 13:34:18.336: e/androidruntime(14109): @ dalvik.system.nativestart.main(native method) 07-19 13:34:18.336: e/androidruntime(14109): caused by: java.lang.nullpointerexception: println needs message 07-19 13:34:18.336: e/androidruntime(14109): @ android.util.log.println_native(native method) 07-19 13:34:18.336: e/androidruntime(14109): @ android.util.log.e(log.java:231) 07-19 13:34:18.336: e/androidruntime(14109): @ com.example.videdrome.videoactivty.oncreate(videoactivty.java:41) 07-19 13:34:18.336: e/androidruntime(14109): @ android.app.activity.performcreate(activity.java:5104) 07-19 13:34:18.336: e/androidruntime(14109): @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1080) 07-19 13:34:18.336: e/androidruntime(14109): @ android.app.activitythread.performlaunchactivity(activitythread.java:2144) 07-19 13:34:18.336: e/androidruntime(14109): ... 11 more
i have been doing similar thing using bundle
final intent notificationintent = new intent(context, a.class); notificationintent.putextras(extra); final pendingintent intent = pendingintent.getactivity(context, 0, notificationintent, pendingintent.flag_update_current); where bundle :
final bundle = new bundle(); extra.putstring("message", "hello"); you can retrieve value of bundle in oncreate of started activity:
final bundle = getintent().getextras(); if (extra != null) { string message=extra.getstring("message"); } moreover , can use flag pendingintent.flag_update_current
this flag works this:
if described pendingintent exists, keep replace data in new intent. can used if creating intents extras change, , don't care entities received previous pendingintent able launch new extras if not explicitly given it.
Comments
Post a Comment