How to show AlertDialog When Application in Foreground Android? -
i have program responsible show alertdialog when in foreground after several seconds:
activitymanager = (activitymanager) getsystemserv(); if (am != null) { list< activitymanager.runningtaskinfo > taskinfo = am.getrunningtasks(1); if (taskinfo != null && !taskinfo.isempty()) { if (taskinfo.get(0) != null && taskinfo.get(0).topactivity != null) { if (!my_class_name.equalsignorecase(taskinfo.get(0).topactivity.getclassname())) { new alertdialog.builder(this).setmessage("aaaaaaaaaaaaaaaaaaaaaaaaaaaa?") .settitle("message").setpositivebutton("yes", new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int which) { } }) .setnegativebutton("no", new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int which){ } }).show(); } } } } but alertdialog didn't show when app go foreground! pls me! thanks!
you can't show dialog service. instead use activity themed dialog, set theme activity (in manifest) this:
android:theme="@android:style/theme.dialog" also, shouldn't use timertask, use handler instead, this: http://developer.android.com/resources/articles/timed-ui-updates.html
Comments
Post a Comment