android.view.WindowManager$BadTokenException:Unable to add window -- token null is not for anapplication
分析:
問題在於newAlertDialog.Builder(Context),雖然這裏的參數是AlertDialog.Builder(Contextcontext)
但我們不能使用getApplicationContext()獲得的Context,而必須使用Activity的Context對象,因爲只有一個Activity才能添加一個窗體。
解決方法:
將new AlertDialog.Builder(Contextcontext)中的參數用Activity的Context對象即可.