Share via


Why would OnPause and OnResume get called while the app is still the currently active app?

Question

Friday, January 25, 2019 6:50 PM

I'm running into an oddity where the OnPause and OnResume methods are being called after the app has been sitting, unused, for about 55-60 seconds or so. The screen isn't locking and the app isn't being backgrounded. It calls the OnPause method followed immediately by a OnResume call. Now this is a problem for the application because it's not uncommon to leave the app running on the phone. Much of the functionality limits what a user is able to do until the GPS has been able to accurately assess their location and detect that they are within a certain range of a pre-determined location. For some phones this can take a while, especially if they don't have a particularly good signal. When OnResume gets executed, it performs a couple of tasks to check some things and a loading screen is displayed. What ends up happening now is the loading screen is presented to the user after 20 seconds or so not doing anything. Depending on the connection, it can take a minute for everything to be analyzed and the loading screen to go away. I won't go into detail but this delay can present some problems for the user.

It's worth noting that we recently updated the SDK and are in the process of updating the APP to work with the latest tools. I don't recall anything like this occurring before the update. Is this normal behavior for Android?

All replies (2)

Monday, January 28, 2019 7:35 AM âś…Answered

If you don't use the app for about 55-60 seconds or so, the page you see is no longer active even we can still can see the page. From the Understand the Activity Lifecycle, from the diagram of the activity lifecycle of this document, we can see the method onPause will be called when another activity comes in the foreground , meanwhile the current activity is still visible for users,but the current page loses focus. This state is just what you said. When the app has been sitting, unused, for about 55-60 seconds or so,the android OS will do something to protect the system,eg. save the power, so we can still see it ,but it indeed lost the focus.

So when we reuse the app, we will call the method: onPause()-->onResume() .


Friday, January 25, 2019 7:23 PM

Well, after doing some testing, it only appears to do this twice back to back after the initial 55-60 seconds wait. I can then wait and it doesn't happen again. If I background the app and bring it back up, it will do the same thing after the initial wait period and then do not do it again.