Android display a screen only the first time you open the application

Asked

Viewed 1,408 times

4

Is there a way to run a specific screen (such as identification) the first time the application opens? And every time I launch an update on google play, people who already have the app installed and open again after the update, will the ID screen appear again? there is a way to differentiate those who download to those who receive an update?

1 answer

5


Use the Sharedpreferences to save the app version.

In the main activity, in the method oncreate(), obtain that information and act accordingly.

String appVer = "versão actual da sua app";
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
String appVer = preferences.getString("lastAppVer","");

if(lastAppVer == ""){
    // A aplicação foi instalada pela primeira vez
    // Exibir tela
}
else if(lastAppVer != appVer){
    // A aplicação foi actualizada
    // Exibir tela
}

On the screen activity to be displayed only once save your app version to Sharedpreferences

String appVer = "versão actual da sua app";
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
preferences.edit.putString("lastAppVer",appVer).apply();  
  • Thank you very much!

  • My context is in red, because?

  • @Evandroaguiar context is an object of the type Context. If you’re using the code on a Activity replace with this.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.