Ionic foreground and background - store state of application

Please describe the question in detail and share your code, configuration, and other relevant info. I have an issue with the app and background working. Can anybody help me?

I made an app for the clinic and all works well while they are in-app but when for example pick up the phone or want to reply to a message looks the state of the app lose and they can’t navigate through the application (the back button dissipated) and need to kill the app and start it again. Is there any solution to it?

I made a “hack” in the app.component.ts file:

App.addListener('appStateChange', ({isActive}) => {
  if (!isActive) {
    // App went to background
  } else {
    // App went to foreground

but when I add that user can’t take a picture of the patient or change his avatar, it always backs him on the homepage :frowning: I use a capacitor to build apps. Is there any solution to save the state to not lose on which page the user exists and where he can go back?

For my Ionic Vue app, I use a combination of the Capacitor Preferences plugin and Ionic Storage to store state. While the app is running, Vuex (Vue’s older state management) is used which is synced with the aforementioned storage so Vuex can be re-populuated on a cold start of the app.

I don’t believe you can control when Android or iOS decides to kill the app. It’s all based on current resources and power saving. If you need the app to return to where the user was on a cold start, then you would probably need to store the current page they are on using one of the mentioned plugins and upon app start, get their last page and redirect them there.

@twestrick thank you for your comment. Do you have some example/demo/tutorial for it?

You can check out this post where I have some more comments and shared some code.