I tried to find a solution to my problem already in google and here on stackoverflow, however nothing could answer my question.
I use a sqlite database to populate a listview. Also on top of the listview there is a tabhost where one can switch to a different activity. When switching to that activity and back then back again to the listview a leak is found. However whatever try there is apparently a leak. Can someone help me in finding that leak?
Here is the listview activity:
@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();
}
The tabhostactivity is quite simple:
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);
Can anyone spot the leak?
Thanks in advance for you help.
Can you get source of contacts.class and incomingcallpopup.class?
The problem is that you try to connect to db twice when switch between tabs (you don’t close db connection in the first tab).
I had this problem in my project when I had 2 SlqHelpers to 1 db and use them at the same time.