Where is the most appropriate place to call the OpenHelperManager.releaseHelper(); in a custom adapter.
For additional context, this adapter is being called in a fragment with a ListView.
Follow from the code snippet below below.
public class CustomAdapter extends BaseAdapter {
private DatabaseHelper mDatabaseHelper;
private RuntimeExceptionDao<SomeObject, Long> dao;
private List<SomeObject> mList;
private Context context;
public CustomAdapter(Context context) {
this.context = context;
mDatabaseHelper = OpenHelperManager.getHelper(context, DatabaseHelper.class);
dao = mDatabaseHelper.getRuntimeExceptionDao();
mList = dao.queryForAll();
}
@Override
public int getCount() {
return mList.size();
}
@Override
public Object getItem(int position) {
return mList.get(position);
}
@Override
public long getItemId(int position) {
return mList.get(position).getId();
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View row = layoutInflater.inflate(R.layout.item, parent, false);
TextView title = (TextView) row.findViewById(R.id.txtTitle);
SomeObject obj = mList.get(position);
title.setText(obj.getTitle());
return row;
}
}
Well, as the original author of OpenHelperManager, I'd strongly advise you not use it. Ever. You don't need reference counting, and you don't need to close your DB. Use OrmLiteSqliteOpenHelper directly.
My blog post, where I explain how I wrote that thing, and why you don't need it.
http://touchlabblog.tumblr.com/post/24474750219/single-sqlite-connection
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With