You will need to create this control in your app’s Start Activity to check the app version and delete what you want if you change the version
This commented in the code how the control should work.
Activity LAUNCHER:
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Pegar acesso ao SharedPreferences
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
// Pegar a ultima versão armazenada, se for uma versão anterior a implementação deste
// controle, vai retornar "0" e fara a limpeza da mesma forma.
String lastVersion = prefs.getString("APP_VERSION", "0");
// Pegar a versionName do build.gradle
String currentVersion = getAppVersion(this);
// Verificar se mudou a versão
if (!lastVersion.equals(currentVersion)) {
// Apagar SharedPrefs
// Apagar BD
// Apagar o que for preciso
// Colocar no Prefs a versão atual para só limpar de novo na proxima att
prefs.edit().putString("APP_VERSION", currentVersion).apply();
}
}
/**
* Rotina para pegar o versionName do build do app
* @param context
* @return version name do arquivo build.gradle
*/
private String getAppVersion(Context context) {
String result = "";
try {
result = context.getPackageManager()
.getPackageInfo(context.getPackageName(), 0)
.versionName;
result = result.replaceAll("[a-zA-Z]|-", "");
} catch (PackageManager.NameNotFoundException e) {
Log.e(context.getClass().getSimpleName(), e.getMessage());
}
return result;
}
}
Build.Gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "br.com.a2sistemas.myapplication"
minSdkVersion 14
targetSdkVersion 28
versionCode 2 // Trocar este numero a cada att
versionName "2.0" // Trocar este numero a cada att
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.0-beta01'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0-alpha4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4'
}
data where? Shared Preferences? Sqlite? Firebase?
– Marceloawq
From Firebase (Information that is stored on the mobile, not on the server) but by guarantee I need to delete everything that is stored in the App, because even uninstalling, and installing again, the old data continues to.
– michaelsc