Using ORMLite with Fragments

android-fragmentactivity, android-fragments, ormlite

Solution

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;
        }
    }
}

Problem

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. :)

Original source