Skip to content Skip to sidebar Skip to footer

Api 8 - Asynctask Nullpointerexception After 2 Rotates

I start an AsyncTask in the onStart() method, because I want it to always reload the data from the SQLite database when the user returns to that Fragment. This is because it is a

Solution 1:

Here is my solution for now. If anyone knows of a better one, please post it.

@OverridepublicvoidonStart() {
    super.onStart();
    mProgressBarLayout.setVisibility(View.VISIBLE);
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.FROYO) {
        newgetItemsAsync().execute(mType);  // Do the AsyncTask for API 10+
    } else {
        // For FROYO only, do the operation on the main thread
        mItemsList = DatabaseManager.get(mParentActivity).getItems(mType);
        mProgressBarLayout.setVisibility(View.GONE);
        if (mItemsList != null) {
            mAdapter = newMyAdapter(mParentActivity, mItemsList);
            setListAdapter(mAdapter);
        }
    }
}

This works.

Post a Comment for "Api 8 - Asynctask Nullpointerexception After 2 Rotates"