Skip to content

Properly detect when the app goes to the background - #4036

Merged
maxme merged 2 commits into
developfrom
issue/4033-manage-background-app-state
May 17, 2016
Merged

Properly detect when the app goes to the background#4036
maxme merged 2 commits into
developfrom
issue/4033-manage-background-app-state

Conversation

@daniloercoli

Copy link
Copy Markdown
Contributor

Fixes #4033 by adding a Timer and a TimerTask that handles all the onBackground code. [Details below].

As explained in the ticket the current implementation doesn't detect when the app goes to background in case of device running in "low memory" condition.

I've tried different solutions, but this one was the most reliable to me.
The proposed solution use the methods onActivityPaused and onActivityResumed of ApplicationLifecycleMonitor to start and stop the timer that detects when the app goes to background.

So in the case when the user is simply navigating between the activities, the onActivityPaused() starts the timer, but almost immediately the new activity being entered, the ApplicationLifecycleMonitor cancels the timer in its onActivityResumed method. And so mIsInBackground would be false.
In the case the app is sent to background, the TimerTask is executed and the code that handles all the background logic is run.

Please, double check that everything is working fine with Dialogs and Prompts.

@daniloercoli daniloercoli added this to the 5.4 milestone Apr 29, 2016
@maxme maxme self-assigned this May 5, 2016
@maxme

maxme commented May 16, 2016

Copy link
Copy Markdown
Contributor

@daniloercoli I've been testing this for some time now with adb logcat | grep background > background.log just to make sure every "App comes from background" always had his "App goes to background".

Code looks good, but can you add some comments on top of startActivityTransitionTimer() to explain what's going on.

@daniloercoli

daniloercoli commented May 16, 2016

Copy link
Copy Markdown
Contributor Author

@maxme - Added comments that describe our onBackground detection library routine.

@maxme

maxme commented May 17, 2016

Copy link
Copy Markdown
Contributor

:shipit:

@maxme
maxme merged commit 52549d3 into develop May 17, 2016
@maxme
maxme deleted the issue/4033-manage-background-app-state branch May 17, 2016 07:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants