mi consiglia di utilizzare le SharedPreferences per questo:
L'idea di base è quella di leggere le SharedPreferences e cercare un valore booleano che non esiste lì al primo avvio dell'applicazione. Per impostazione predefinita , verrà restituito "true" se non è stato possibile trovare il valore cercato , a indicare che si tratta in effetti della prima avvio dell'app. Quindi, dopo aver avviato la prima app, verrà archiviato il valore "false" nelle tue SharedPreferences e al successivo avvio verrà letto il valore "false" dalle SharedPreferences, indicando che è non più la prima app avvia.
Ecco un esempio di come potrebbe apparire come:
@Override
protected void onCreate(Bundle savedInstanceState) {
// your other code...
// setContentView(...) initialize drawer and stuff like that...
// use thread for performance
Thread t = new Thread(new Runnable() {
@Override
public void run() {
SharedPreferences sp = Context.getSharedPreferences("yoursharedprefs", 0);
boolean isFirstStart = sp.getBoolean("key", true);
// we will not get a value at first start, so true will be returned
// if it was the first app start
if(isFirstStart) {
mDrawerLayout.openDrawer(mDrawerList);
Editor e = sp.edit();
// we save the value "false", indicating that it is no longer the first appstart
e.putBoolean("key", false);
e.commit();
}
}
});
t.start();
}
fonte
2013-08-27 21:14:18