0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[Android]高速に何度も画面遷移する際にクラッシュする[Unable to add window]

Posted at

エラー内容

繰り返し画面の遷移を行っている際に時々アプリのクラッシュが起こっていた。
エラー内容は下部。

android.view.WindowManager$BadTokenException: Unable to add window"

解決方法

調べたところContextの拡張関数でAlertDialogを作成していた場面でエラーが起きていた。
ダイアログ生成時に呼び出し元のContextが終了していると起きるらしく、そのため繰り返し高速に画面遷移を行っていた場合に起きていた。

なので作成した拡張関数内で

fun Context.function(){
    if(this is Activity){
        if (this.isDestroyed || this.isFinishing) {
            return
        }
    }
}

としてやれば修正された。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?