android - POPUP on Boot Completed -
trying create popup after every boot completed confirmation. able boot_completed message while opening alertdialog crashing, below code lines using. please suggest
public class bootreceiver extends broadcastreceiver { private static final string tag = "bootreceiver"; @override public void onreceive(context context, intent intent) { string action = intent.getaction(); log.d(tag, "broadcastreceiver:" + action); if (action.equals(intent.action_boot_completed)) { log.d(tag, "action_boot_completeted receved" ); charsequence text = "boot completed!"; int duration = toast.length_short; toast.maketext(context,text,toast.length_short).show(); alertdialog.builder alertdialog = new alertdialog.builder(context); alertdialog.setmessage("message"); alertdialog.settitle("consent"); alertdialog.seticon(android.r.drawable.ic_dialog_alert); alertdialog.setcancelable(false); alertdialog.setpositivebutton("agree", new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int which) { log.d(tag, " agree clicked" ); } }); alertdialog.setnegativebutton("disagree", new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int which) { log.d(tag, " disagree clicked" ); } }); alertdialog.show(); } } }
back trace :
i/activitymanager( 109): start proc com.android.mms broadcast com.android.m ms/.transaction.mmssystemeventreceiver: pid=311 uid=10015 gids={3003, 1015} e/androidruntime( 246): fatal exception: main e/androidruntime( 246): java.lang.runtimeexception: unable start receiver co m.android.settings.bootreceiver: android.view.windowmanager$badtokenexceptio n: unable add window -- token null not application e/androidruntime( 246): @ android.app.activitythread.handlereceiver(act ivitythread.java:1862) e/androidruntime( 246): @ android.app.activitythread.access$2400(activi tythread.java:124) e/androidruntime( 246): @ android.app.activitythread$h.handlemessage(ac tivitythread.java:1035) e/androidruntime( 246): @ android.os.handler.dispatchmessage(handler.ja va:99) e/androidruntime( 246): @ android.os.looper.loop(looper.java:126) e/androidruntime( 246): @ android.app.activitythread.main(activitythrea d.java:3897) e/androidruntime( 246): @ java.lang.reflect.method.invokenative(native method) e/androidruntime( 246): @ java.lang.reflect.method.invoke(method.java:4 91) e/androidruntime( 246): @ com.android.internal.os.zygoteinit$methodanda rgscaller.run(zygoteinit.java:841) e/androidruntime( 246): @ com.android.internal.os.zygoteinit.main(zygot einit.java:599) e/androidruntime( 246): @ dalvik.system.nativestart.main(native method) e/androidruntime( 246): caused by: android.view.windowmanager$badtokenexception : unable add window -- token null not application e/androidruntime( 246): @ android.view.viewroot.setview(viewroot.java:4 34) e/androidruntime( 246): @ android.view.windowmanagerimpl.addview(window managerimpl.java:181) e/androidruntime( 246): @ android.view.windowmanagerimpl.addview(window managerimpl.java:95) e/androidruntime( 246): @ android.app.dialog.show(dialog.java:269) e/androidruntime( 246): @ android.app.alertdialog$builder.show(alertdia log.java:853) e/androidruntime( 246): @ com.android.settings.bootreceiver.onrecei ve(xtrabootreceiver.java:53) e/androidruntime( 246): @ android.app.activitythread.handlereceiver(act ivitythread.java:1855) e/androidruntime( 246): ... 10 more
a dialog needs activity context. have service. options are:
- use toast.
- create activity , give dialog theme.
- there may third option create or obtain suitable context, i'm not aware of one.
Comments
Post a Comment