Can Activity.getIntent() ever return null?

后端 未结 2 1187
野趣味
野趣味 2020-12-03 06:45

Can Activity.getIntent() ever return null?

The documentation does not mention this as a possibility, so I am wondering if I have to check the result of

2条回答
  •  囚心锁ツ
    2020-12-03 06:58

    It CAN be null when Your application was updated from the market while it was in the memory and relaunched again after the update. Maybe even If you will make update manually by Studio, or from .apk file, the same effect will be. Not sure, sorry.

    I once updated application in Google Dev console and got several different NPE in Crashlitics in the lines with call getIntent(). It happened for all screens, where I used getIntent().getExtra() onCreate or even later in lifeCycle.

    So... It looks ugly, but to avoid crashes I need to check intent for NULL value all the time I call getIntent and most of the times I call Finish() if the intent is null. But you can make other logic, ofc, for you purpose.

提交回复
热议问题