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!
– Diego Figueiredo
My context is in red, because?
– Evandro Aguiar
@Evandroaguiar
context
is an object of the type Context. If you’re using the code on a Activity replace withthis
.– ramaral