我试图在google和stackoverflow中找到我的问题的解决方案,但是没有什么能回答我的问题。 我使用sqlite数据库来填充listview。此外,在列表视图的顶部还有一个tabhost,可以切换到不同的活动。当切换到该活动然后返回到列表视图时,会发现泄漏。无论如何,显然有泄漏。有人可以帮助我找到泄漏吗?
以下是listview活动:
@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 :(得分:1)
你能获得contacts.class和incomingcallpopup.class的来源吗?
问题是您在选项卡之间切换时尝试连接到db两次(您没有在第一个选项卡中关闭数据库连接)。
当我有2个SlqHelpers到1分贝并同时使用它时,我的项目出现了这个问题。