2012-02-23 63 views
0

我使用的查询抽取数据库,什么是暂时存储数据的最佳实践。目前我使用ArrayList来提取数据,但我认为这可能不是最好的设计实践。如何保存从游标中提取数据库中的Android

感谢

  Cursor cur5 = database2.rawQuery("select ID from Quote where EmoticonID=? and SubCategoryID=?" ,new String [] {Integer.toString(gcid), Integer.toString(scid)}); 
      if(cur5.getCount()==0){ 
       Log.i("TAG Screen3", "No Quotes ID found for Particular ID"); 

       if (helper2 != null) { 
        helper2.close(); 
       } 

       if (database2 != null) { 
        database2.close(); 
       } 
     }else{ 

      cur5.moveToFirst(); 

     do { 
       quoteid.add(Integer.parseInt(cur5.getString(0))); 
       Log.i("TAG Screen3 Quote ID", (cur5.getString(0))); 

      } while (cur5.moveToNext()); 

      if(cur5 != null){ 
       cur5.close(); 
      } 

      if (helper2 != null) { 
       helper2.close(); 
      } 

      if (database2 != null) { 
       database2.close(); 
      } 
    }  
+0

“抽取数据库”?你什么意思?你正在提取数据库中的所有**数据?你能显示查询吗? – m0skit0 2012-02-23 12:13:10

+2

在少量数据的情况下,您可以使用SharredPreferences – Android 2012-02-23 12:13:19

+0

作为一种观察,存在大量不必要的代码和重复数据。 'cur5.moveToFirst()'可以像'cur5.moveToFirst()'一样去'; if(cur5.getCount()');将它修剪成一个'while(cur5.moveToNext())'循环,你的代码大小约为一半 – 2012-02-23 12:42:29

回答

2

那么如果你已经有一个数据库,从获取数据,为什么不使用数据库作为临时存储。只需从数据库中获取数据即可跳过临时存储。

如果你仍然想在本地存储在手机上,我建议对巨型对象或POJO的本地SQLite数据库。如果您有基本类型的键值对,则应使用SharedPreferences。

欲了解更多信息,请参阅http://developer.android.com/guide/topics/data/data-storage.html

或者给我们介绍一下你的数据,你打算做:)这可能会帮助我们在帮助你什么的一些信息;)

+0

我认为POJO可能是最好的设计模式。 – Programmer 2012-02-24 05:36:50

相关问题