Before you start developing for android you should know the life cycle of an 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 on this link . Note: it is in English.