Mi aplicación copia archivos desde res/raw a la tarjeta sd en la primera ejecución. Quiero que actualice esos archivos en cada actualización de la aplicación posterior. ¿Cómo puedo hacer que restablezca la primera preferencia en verdadero en cada actualización de la aplicación?Android: ¿Cómo reiniciar FirstRun SharedPreferences cuando mi aplicación se actualiza?
Este es el código correspondiente:
/**
* get if this is the first run
*
* @return returns true, if this is the first run
*/
public boolean getFirstRun() {
return mPrefs.getBoolean("firstRun", true);
}
/**
* store the first run
*/
public void setRunned() {
SharedPreferences.Editor edit = mPrefs.edit();
edit.putBoolean("firstRun", false);
edit.commit();
}
SharedPreferences mPrefs;
/**
* setting up preferences storage
*/
public void firstRunPreferences() {
Context mContext = this.getApplicationContext();
mPrefs = mContext.getSharedPreferences("myAppPrefs", 0); //0 = mode private. only this app can read these preferences
}
public void setStatus(String statustext) {
SharedPreferences.Editor edit = mPrefs.edit();
edit.putString("status", statustext);
edit.commit();
}
}
Gracias ¡por tu respuesta! Odio preguntar demasiado ... pero, ¿podrías proporcionar un fragmento de código? Entiendo lo que dices, pero tengo problemas para descubrir cómo implementarlo ... –
@ La respuesta de RivieraKid contiene el tipo de implementación que tenía en mente, creo que puedes usar su respuesta –