如果.putExtra("key",boolean)中的键不存在,该值是多少

Bry*_*n P -3 android android-intent

如果我getIntent().getExtras().getBoolean("key")不使用该.putExtra("key",boolean)方法,那么价值是多少?

它不接受,!= null因为它是布尔所以任何要点?

lop*_*ael 6

我的解决方案

boolean defaultValue = false;
boolean yourValue = getIntent().getBooleanExtra(YOUR_EXTRA, defaultValue);
Run Code Online (Sandbox Code Playgroud)

如果您没有生成putExtra,您的意图将具有您已确定的默认值.

我希望我帮助过你!