Application Entered Background -> bubble user logout?


Huy guys,

is there a way to always logout my user when the Application Entered Background , so when I open it again it will ask me for my credentials, either by keyboard or touch id / face id (already implemnted) , I have the app connected to the bubble backend.

I am trino to develop my app as secure as possible and this is a requirement I would need.



Yes you can trigger events when app moves to the background here…


Yes, I tried. But doesn’t allowed me to trigger a run api or go to page event.
So I really do not know how to logout when goes to the background . Is there a way to “disconnect “ the app without an api request for logout? Like a “hard logout” when the api goes to the background?. I tried giving the token login an empty value when the app goes to the background, but when the app is opened again it only disconnect and “logout” when request something from the backend and in the meantime it shows where it was previously . It does not disconnect immediately. What I need is always ask me for credentials when the app is vslled from background or just opened.


Good question and ideas for success here.

How about a Device variable that you use as a stopgate. When the app goes to background, flip the Boolean to true or false. Then when the app comes back up, check to see if it’s in the logged out position. If it is, make the appropriate login api request and when successful, change that Boolean to your logged in true/false position.

My thinking is that you can essentially create your own checkpoint using a device variable here.


I am trying with no luck so far, I will let you know if I can do it.


Sounds good. This fork in the road should work for you. Feel free to ask more questions. I broke down the workflow here if this helps.


Thank you @Wade, I really appreciate you write it down.
Actually I tried this, but what I actually need it is the app to automatically logout when enter to Background or Foreground, I tried giving the token to auth an empty value, but when the app goes to foreground it takes some second to recognize the token is null an then goes to the login page, and this delay I can not accept. I will kept trying.


I understand your frustration but I don’t think you’ll beat the delay. Even my TD Ameritrade app delays before kicking in the auto-login. Would you consider the idea of adjusting the screen when the app goes into the background? You could display an imageview of whatever you want so that it’s the 1st thing they see when they go back into the app. Perhaps it’s a middle area while the app checks for token auth, etc?


Thank you @wade but still not working, the limitation here is that when the app calls something when going to background or foreground I can only set values for device variable and not page variables, and that makes total sense, because this actions are related to the app itself and not the page you are in the moment when you enter or leave background. I could say to the page show something when page load if certain variable is true, but this doesn’t work either, because the page has to be called, and when enter foreground not page is loaded, the app just goes where it was when went to background, so nothing is trigger in the page.
I could call a touch id /faceid when enter foreground, to check if users is who is supposed to be, but this has a cancel button, again, not working the way I need it, because te app resumes where it was before if I just hit cancel in the face id notification.

I will keep thinking!


If you switched to using a Device Variable instead of a Page Variable, would that get you what you need? You’re definitely able to use it. The big difference is that Device Variables are accessible in any page. You don’t HAVE to access them anywhere else, it’s just a difference in scoping really.

Can you use that to make the trigger you need to do something when you need it to happen?


A page variable would do the trick, the problem it’s you can’t “call them” set a value to a page variable when going to background or foreground, only when page load or inside the page, but because the page is already loaded when you go to foreground a device variable wouldn’t do anything (you can only set values on foreground or background to device variables). Is there an action like “reload page” when go to foreground? That would do it too.