开发者

Saved data lost when I restart the application(android)

I'm saving some records through my application in SQLite database and later retrieving those records for future use.

It's working fine until I close my application.

When I close m开发者_Python百科y application all the previously saved record becomes zero.

Here is the code:--

 public long insertAlbum(long Outlet_id,long user_id,String Remarks,String PhotoName,String ReportId,String Date,String Status,String LocalRepId)
 {
     long rowId=0;

     ContentValues initialValues = new ContentValues(); 
     initialValues.put("web_AlbumId", 0);
     initialValues.put("OutletId", Outlet_id);
     initialValues.put("Remarks", Remarks);
     initialValues.put("UserId", user_id);
     initialValues.put("Usr_Entdt", Date);
     initialValues.put("PhotoName", PhotoName);
     initialValues.put("ApprovedYN", "Pending");
     initialValues.put("Status", Status);
     initialValues.put("ReportId", ReportId);
     initialValues.put("LocalReportId", LocalRepId);
     try
     {
         myDataBase.beginTransaction();
      rowId=  myDataBase.insertOrThrow("Album", null, initialValues);
      myDataBase.setTransactionSuccessful();

     }
     catch(SQLException e)
     {
         e.printStackTrace();
     }
     finally
     {
         myDataBase.endTransaction();
     }
     return rowId;


This shouldn't happen. Sounds to me like you're recreating the database when you're opening the database. Check your code to make sure it's correct


Without seeing your code, it's hard to say what's going on. However, my suspicion is that your code is ALWYAYS creating the database. Are you extending the SQLiteOpenHelper class to create your database? Check there or post the code for further assistance.


Go to to folder where your Sqlite Db file created and check in that file whether the data you saved is present or not . If the data is present in the DB then you need to Retrieve the data from DB

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜