How do I tell if Intent extras exist in Android?

前端 未结 5 666
你的背包
你的背包 2020-12-23 09:46

I have this code that checks for a value of an extra in an Intent on an Activity that is called from many places in my app:

getIntent().getExtras().getBoolea         


        
5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-23 10:00

    getIntent() will return null if there is no Intent so use...

    boolean isNewItem = false;
    Intent i = getIntent();
    if (i != null)
        isNewItem = i.getBooleanExtra("isNewItem", false);
    

提交回复
热议问题