0

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
    this.navCtrl.navigateRoot(['./']);
  }
});

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 :( 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?

mrakodol
  • 1,143
  • 3
  • 12
  • 41

1 Answers1

0

I believe that method would work but you need an extra method inside, sounds like you need capacitor-background-task plugin by capawesome. then you would need to store the values and route to the local storage, so when users comeback in your app, it would save the state they were in.

  • Thank you for this plugin. But I didn't understand how to make that part of the code instead of navigating to root :( Can you help me? – mrakodol Mar 17 '23 at 14:39
  • Look at the example provided in the plugin. Then inside the plugin callback, add logic to get the route the user is currently on, then save that string to local storage. This should be saved in a service file. That way you an add this logic to any component that needs the route to be saved. The component that will use this service will then need logic in the ngOninit lifecycle method to get the route from local storage. – StackoverBlows Mar 17 '23 at 19:02
  • can you make me an example? – mrakodol Mar 18 '23 at 05:11