Android Question Activity_Resume called immediately after Activity_Pause

JamesD

New Member
Licensed User
Longtime User
I'm building my first app, a game, but I'm having trouble with pause and resume.

The app is running, and then I press the home button or off button. From logging I can see that it calls Activity_Pause where I set the Timer1.enabled = false. This obviously stops the timer, and the app should pause with everything in the state that it is in.

However, a couple of seconds later, without me touching the phone (which is still off), I see that Activity_Resume is automatically called. This has the line Timer1.enabled = true. And so the the app starts again and continues working away in the background. But since the phone is off I don't want this. I want it to pause completely (whilst remembering everything), and the timer start again only when I go back to the app.

I think I'm probably missing something fairly fundamental here... is there something I need to do to stop the app running in the background? I thought that Activity_Resume would only be called when I went back to the app on the phone, not automatically straight after Activity_Pause.

Thanks for any help...
 

JamesD

New Member
Licensed User
Longtime User
I'm building my first app, a game, but I'm having trouble with pause and resume....

Having tested this further, I have narrowed down the issue. The problem does not occur when I simply press the Home button, and use other apps for a bit, before returning to my app. In that case, it stays within Activity_Pause until I return to my app.

The issue occurs when the phone goes to sleep, i.e. the screen goes off. At that point, Activity_Resume runs and the app continues, even though the phone is sleeping.
 
Upvote 0
Top