Is it a good idea to call finish() after starting a new Activity in Android?

前端 未结 2 2021
既然无缘
既然无缘 2020-12-30 22:08

Like:

startActivity(intent);
finish();

Without calling finish() explicitly, onDestroy() is not called for the former Activity,

2条回答
  •  生来不讨喜
    2020-12-30 22:48

    Doing this is fine if you don't need an instance of that Activity. So when you press back on the next Activity know that you won't come back to this one but whatever is on the stack below where that Activity was or the home screen if there are no more.

    However, I'm not sure this is why you are getting an OOM exception and you should probably figure out where that is coming from instead. If you are using Bitmaps then that could be causing the exception.

提交回复
热议问题