2012-03-28 22 views
0

我試圖找到一個解決我的問題已經在谷歌和這裏的計算器,但沒有什麼能回答我的問題。 我使用sqlite數據庫來填充列表視圖。在列表視圖的頂部還有一個tabhost,可以切換到不同的活動。當切換到該活動並返回到列表視圖時發現泄漏。然而無論如何嘗試顯然是泄漏。有人能幫我找到泄漏嗎?tabhost和ListView SQLite數據庫產生漏

這裏是列表視圖活動:

@Override 
    protected void onCreate(Bundle savedInstanceState) { 
     // TODO Auto-generated method stub 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.contacts); 

     contactlist = (ListView) findViewById(R.id.list); 

     entry.open(); 
     c = entry.getData(); 
     startManagingCursor(c); 

     String[] from = new String[] {"_id", "firstname", "lastname"}; 
     int[] to = new int[] {R.id.iVPI, R.id.tvfirstName, R.id.tvlastName}; 

     adapter = new MySimpleCursorAdapter(this, R.layout.contacts_list_item, c, from, to); 
     contactlist.setAdapter(adapter); 

     contactlist.setOnItemClickListener(new OnItemClickListener() { 
      @Override 
      public void onItemClick(AdapterView<?> arg0, View v, int position, long id) { 
       // TODO Auto-generated method stub 
       Intent intent = new Intent(contacts.this, contactsdetails.class); 
       Cursor cursor = (Cursor) adapter.getItem(position); 
       intent.putExtra("ID", cursor.getInt(cursor.getColumnIndex("_id"))); 
       c.close(); 
       startActivity(intent); 
      } 
     }); 
    } 

    protected void onStart() { 
     super.onStart(); 
     entry.open(); 
    } 

    protected void onPause() { 
     super.onPause(); 
     entry.close(); 

    } 
    protected void onStop() { 
     super.onStop(); 
     entry.close(); 
    } 
    protected void onDestroy() { 
     super.onDestroy(); 
     entry.close(); 
    } 

的tabhostactivity很簡單:

th = getTabHost(); 
     th.addTab(th.newTabSpec("tag1").setIndicator("Contacts", getResources().getDrawable(R.drawable.book)).setContent(new Intent(this, contacts.class))); 
     th.addTab(th.newTabSpec("tag2").setIndicator("Profile", getResources().getDrawable(R.drawable.mailbox)).setContent(new Intent(this, incomingcallpopup.class))); 
     th.setCurrentTab(0); 

任何人都可以發現泄漏?

在此先感謝您的幫助。

+0

泄漏情況如何報告?嘗試用於eclipse的內存分析工具插件,它會告訴你什麼對象與更多的數據一起泄漏。 – Bondax 2012-03-28 18:28:35

回答

1

你能contacts.class和incomingcallpopup.class的來源?

的問題是,你嘗試連接時,切換選項卡(你在第一個選項卡不能關閉數據庫連接)DB的兩倍。

我在我的項目有這個問題時,我有2個SlqHelpers 1 DB和在同一時間使用它們。

+1

謝謝你是對的。我在incomingcallpopup.class中犯了一個愚蠢的錯誤,在那裏我太晚關閉了數據庫。太感謝你了,我花了你的時間瀏覽我的代碼。 – Max 2012-03-28 20:10:42