Change "state/view" before go in background

Hi all, I’m creating an app that when resumed from background need to show the user a pin request. I have created a “state” with this pin request, I have linked this “state” change with an eventlistner on “resume” event and all works.

This is the code:

document.addEventListener("pause", function(){ 
		if ($ != "info" && Pin.isSet()){
			$state.go('pin', {}, { reload: true });       
	}, false);

My problem is when the app resume from background: user does not see immediately the pin “state/page” but the last state/page and after some millisecond the change of state/page (pin request state/page).

I have tried to add a listener on “background” with the same code but nothing is changed.

How can I change state/page of my app before that the app goes to background ?



You see this is the problem, I talked about this in my previous blog article.

When an application is put to the background it’s paused. Everything you’re trying to execute in your code will be executed AFTER app is active again. That’s why you’re seeing a view change, it’s executed after a background state.

To fix this problem use Cordova background mode plugin. This way, when your application is paused, plugin will trigger
onactive event and unpause it, this time in the background:

  cordova.plugins.backgroundMode.onactivate = function() {
       // Trigger state go function

Now you can change state, wait 100-200 ms and disable background mode, thus pausing your app again.

Read this article: Prevent Ionic Application From Pausing In The Background

oh. I try it now…

But: "The plugin focuses on enterprise-only distribution and may not compliant with all public store vendors."
and in the issues there is this where there is a reply that say “Apple reject an app that use this plugin”.

However thanks.


I know this has been couple months, but have you solve your issue?

I ran into the same issue as you, I tried the background plugin as suggested. but seems like it doesn’t work. The UI element does not refresh once it goes into the background (so state.go doesnt work). there still that flicker of last state/view after it resumes.
I know its a long shot, but don’t think this is doable.