The app is "restarted" when I move it to background

Im creating an app and I need to keep working in background but this doesnt work.
Im using:

I am on Visual studio with ionic , so I execute:

ionic cordova run android

The app is launched and working. The first view is a Login, I fill the login and this take me to the second view (thit is a tab page).
On this page I add:

import { BackgroundMode } from '@ionic-native/background-mode/ngx';

constructor(private background: BackgroundMode){

The problem is that when I move the app to the background, is “restarted” . I mean that when I open the app on background it takes me again to the first view where I should do the Login. So this is not working.

Am I doing something wrong? Is visual studio? How can I solve it?


If the device decides that the resources used by your app are better deployed elsewhere, your app gets reaped and restarted when the user wishes to interact with it again. The timing of when this happens is out of your control.

So I would recommend storing whatever state your application holds into someplace persistent and reading it from there upon app launch and/or resumption, if you want to create the illusion that nothing has changed across a pause/resume cycle.

Thanks in first place for ur answer.
This could be a solution, the problem is that this app use a bluetooth device so if the app is “restarted”, the device is disconected. So if u use it when the app is in the background… this doesnt work