Android: Is onPause() guaranteed to be called after finish()?

前端 未结 4 1229
一整个雨季
一整个雨季 2021-01-17 19:09

Couldn\'t find a solid answer to this anywhere. I have a method where finish() is being called, and onPause() is called afterward.

Is onPause() guaranteed to be cal

4条回答
  •  北海茫月
    2021-01-17 20:01

    The system calls this method as the first indication that the user is leaving your activity (though it does not always mean the activity is being destroyed). This is usually where you should commit any changes that should be persisted beyond the current user session (because the user might not come back). so onPause() is guaranteed..The official documentation here

    EDIT 1

    onCreate() is to onDestroy() && onStart() is to onStop() && onResume() is to onPause() .. onStart() is called when onCreate() finishes its work. if not its not called.. onResume() indicates the ui is about to be shown to the user -(An Activity's content is the screen the user sees). if you call finish() in onCreate(), onPause() will be skipped because onResume() was never called same goes to onStart() .. so in some cases you can say its not; but that will be false, because what's an Activity that is not a screen or serve as a container for screens-(Fragment).

    and why would you call finish(); directly in your Activity's onCreate()? From how Activities work in general, onPause() will always guarantee is calling..

提交回复
热议问题