Before you start developing for android you should know the life cycle of an activity (Activity).
When the activity is no longer visible to the user the application is stopped and when the user returns to the app the oncreate will run again.
When this happens we lose the values of the variables, to avoid this we must save the values to recover later.
There are some events like:
//Armazenar valores quando a aplicação é pausada ou parada
@Override
public void onSaveInstanceState(Bundle outState){
super.onSaveInstanceState(outState);
outState.putString("idade", 16);
}
//Recuperar valores armazenados
@Override
public void onRestoreInstanceState(Bundle savedInstanceState){
super.onRestoreInstanceState(savedInstanceState);
}
Take a look at that link. Note: is in English.
That’s normal, that’s how the Android works. The solution depends on each case. Read what the documentation says on the subject.
– ramaral
Hello @ramaral, I edited the question to improve the explanation. I will take a look at the link, thanks.
– Mateus Carvalho
Disappears completely or is the process destroyed? It does not appear in "Recent applications"?
– ramaral
It continues to appear in recent applications, only when I click it goes back to Mainactivity.
– Mateus Carvalho
@The normal is for him to go back to the same Activity he was, but restarting it. If you want to know if this is the effect of the system killing Activity due to lack of resources, turn on the "Do not keep activities" option in the developer settings. Open your program, switch to another and go back to it. If the same effect happens, your problem is the same.
– Pablo Almeida