1
0

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 5 years have passed since last update.

Intentのフラグを解析する

Posted at

AndroidでIntentを受け取ったときにどういうフラグが設定されているかを調べたい時、単純にintent.flagsを参照するだけだと分かりづらかったので、フラグの名称を出力するために以下のコードを書きました。

Intent::class.java.fields.forEach { field ->
  if (field.name.startsWith("FLAG_")) {
    val flag = field.get(null)
    if (flag is Int) {
      if (flag and intent.flags != 0) {
        Log.d("MyApp", "Intent Flag ${field.name}")
      }
    }
  }
}

これでIntent Flag FLAG_ACTIVITY_NEW_TASKなどがログに出力されます。

1
0
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?