ERROR/AndroidRuntime(10104): Caused by: android.view.WindowManager$BadTokenException: Unable to add window -- token android.app.LocalActivityManager$LocalActivityRecord@45a58ee0 is not valid; is your activity running?
原因分析:
因爲new對話框的時候,參數content 指定成了this,即指向當前子Activity的context。但子Activity是動態創建的,不能保證一直存在。其父Activity的content是穩定存在的,所以有下面的解決辦法。
解決辦法:
將content替換爲this.getParent()即可。