2013-07-21 35 views
0

有沒有人知道如何在每次我的應用程序在真實設備中執行時重置數據庫?每當我的應用程序運行時數據庫都會清空

目前,我有這個代碼,但它不工作...

public void doDBCheck() 
    { 
     try{ 
       File file = new File(context.getExternalFilesDir(null).getAbsolutePath()); 
       file.delete(); 
     }catch(Exception ex) 
     { 
      } 
     } 

任何解決方案?

+0

in emulator or real device? –

+0

它在真實的設備上 – edmund02

+0

http://stackoverflow.com/questions/4406067/how-to-delete-sqlite-database-from-android-programmatically –

回答

0
public void clearDatabase() 
{ 
SQLiteDatabase db = helper.getWritableDatabase(); 
db.delete({tablename},null,null) // write this line for each table in your db. 
} 
+0

我會將此代碼添加到我的onCreate()? – edmund02

+0

如果您粘貼了您的活動代碼,這將有所幫助。 –

相關問題