我正在尋找一種顯示對話框的方式,無論顯示何種活動。如何從應用程序實例中觸發對話框?
我想什麼,我想要實現更好的使用一些代碼解釋:
public class MyApp extends Application {
public MyApplication() {
}
@Override
public void onCreate() {
super.onCreate();
boolean success = doSomeWebServiceCall();
if (!success)
showAlertDialog(); // fails with error
}
}
我得到的錯誤是:
ERROR/AndroidRuntime(375): Caused by: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
at android.view.ViewRoot.setView(ViewRoot.java:460)
謝謝,我會試一試! – David 2011-05-18 05:02:07
你給startActivity的背景是什麼? – David 2011-05-18 17:57:35
@David:'Application'是一個'Context'。 – CommonsWare 2011-05-18 17:58:18