Is it possible to use ORMLite to manage your local database while using Android Fragments?
Some example code or links to example code showing how to create something like an ORMLiteFragmentActivity class would be cool. Or I guess a simple "no" might be an acceptable answer. :)
Yup, it's totally possible. See the instructions here. Basically, all you do is create a new class, like you suggested. You can replace Fragment
with any other type that you want to extend. For example, I also have OrmLiteListFragment
which extends ListFragment
public class OrmLiteFragment extends Fragment {
private DatabaseHelper databaseHelper = null;
protected DatabaseHelper getHelper() {
if (databaseHelper == null) {
databaseHelper =
OpenHelperManager.getHelper(getActivity(), DatabaseHelper.class);
}
return databaseHelper;
}
@Override
public void onDestroy() {
super.onDestroy();
if (databaseHelper != null) {
OpenHelperManager.releaseHelper();
databaseHelper = null;
}
}
}
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