onStop() not getting called when I press the back button

前端 未结 3 1630
灰色年华
灰色年华 2021-02-15 23:14

Is this normal.

The docs say

\"The onStart() and onStop() methods can be called multiple times, as the activity alternates between being visible and hidden to th

3条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-16 00:12

    If you still need those to get called for your activity instance when a new instance is created, you can use this hacky solution. Just implement your logic in #doStopOperation() and #doDestroyOperation() instead of #onStop() and #onDestroy() - and be sure to call super#onStop() and super#onDestroy() from your overridden methods. Obviously when extending this activity, you don't need to extend the AppCompatActivity, you can use the regular activity instead. This works for me in a production build, so hopefully it will help.

    I guess you could write a timer hack as well to invoke stop and destroy even when no new instance is created, but that's up to you.

提交回复
热议问题