Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible that isFinishing() returns false in onPause() but returns true in onStop() ?

Tags:

android

I am reading the book "Beginning Android Games,2nd Edition".

The page 129 says

'In onPause(), we simply pause our main loop thread, and if Activity.isFinishing() returns true, we also save to disk any state we want to persist.'

and the author does nothing in the onStop() method.

But the problem is that if isFinishing() returns false in onPause() but returns true in onStop(), we will lose unsaved data if we do not deal with onStop() method.

Any suggestions?

like image 411
user2158697 Avatar asked Oct 21 '22 02:10

user2158697


1 Answers

If isFinishing() returned false in onPause it will also return false in onStop (and also in onDestroy).

I guess that an exception to this could be if you call yourActivity.finish() in the onPause method. If you do that, isFinishing() will return false before you call yourActivity.finish() and true after.

like image 180
pomber Avatar answered Nov 17 '22 07:11

pomber