2012-03-19 45 views
0

IM后的行试图挽救一个排在我的设置表,它的工作原理都非常愉快,除了当我杀死的应用程序,然后试图让行回到它不能找到它sqlite3的犯规保留重启

Cursor c = db.query(savedSettings.getTableName(), null, null, null, null, null, null); 
    c.moveToLast(); 
    DatabaseUtils.dumpCursor(c); 

    db.setTransactionSuccessful(); 
    db.endTransaction(); 

这里就是我做我的收盘:

public void onPause() { 
    db.close(); 
} 

public void onDestroy() { 
    db.close();  
    database.close(); 
} 

public void onStop() { 
    db.close(); 
    database.close(); 
} 

public void onResume() { 
    db = database.getWritableDatabase(); 
} 

我重新启动应用程序后,它失去了它的内容。 任何人都有任何想法。

回答

1

在活动重新启动后保留数据。请考虑使用以下代码段。

@Override 
    protected void onSaveInstanceState(Bundle outState) 
    { 
     Here you will write to things to bundle which you want to preserve 
      after activity restart. 

     super.onSaveInstanceState(outState); 
    } 

    @Override 
    protected void onRestoreInstanceState(Bundle savedInstanceState) 
    { 
     Here you will restore the values. 
     super.onRestoreInstanceState(savedInstanceState); 
    } 

请你的时间投资在读

http://developer.android.com/guide/topics/fundamentals/activities.html#SavingActivityState

希望这有助于。

+0

我的数据必须持续时间比应用程序的一个实例的生命周期长。但是,thx – 2012-03-19 12:42:22