Android Open Source - fieldreporter S Q Lite Cursor Loader






From Project

Back to project page fieldreporter.

License

The source code is released under:

Apache License

If you think the Android project fieldreporter listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.donnemartin.android.fieldreporter;
//from  w  w w. j av  a  2 s . c  om
import android.content.Context;
import android.database.Cursor;
import android.support.v4.content.AsyncTaskLoader;

public abstract class SQLiteCursorLoader extends AsyncTaskLoader<Cursor> {
    private Cursor mCursor;

    public SQLiteCursorLoader(Context context) {
        super(context);
    }

    protected abstract Cursor loadCursor();

    @Override
    public Cursor loadInBackground() {
        Cursor cursor = loadCursor();
        if (cursor != null) {
            // ensure that the content window is filled
            cursor.getCount();
        }
        return cursor;
    }
    
    @Override
    public void deliverResult(Cursor data) {
        Cursor oldCursor = mCursor;
        mCursor = data;
        
        if (isStarted()) {
            super.deliverResult(data);
        }
        
        if (oldCursor != null && oldCursor != data && !oldCursor.isClosed()) {
            oldCursor.close();
        }
    }
    
    @Override
    protected void onStartLoading() {
        if (mCursor != null) {
            deliverResult(mCursor);
        }
        if (takeContentChanged() || mCursor == null) {
            forceLoad();
        }
    }

    @Override
    protected void onStopLoading() {
        // Attempt to cancel the current load task if possible.
        cancelLoad();
    }

    @Override
    public void onCanceled(Cursor cursor) {
        if (cursor != null && !cursor.isClosed()) {
            cursor.close();
        }
    }

    @Override
    protected void onReset() {
        super.onReset();

        // Ensure the loader is stopped
        onStopLoading();

        if (mCursor != null && !mCursor.isClosed()) {
            mCursor.close();
        }
        mCursor = null;
    }

}




Java Source Code List

android.UnusedStub.java
com.donnemartin.android.fieldreporter.DataLoader.java
com.donnemartin.android.fieldreporter.LastLocationLoader.java
com.donnemartin.android.fieldreporter.LocationListCursorLoader.java
com.donnemartin.android.fieldreporter.LocationReceiver.java
com.donnemartin.android.fieldreporter.ReportActivity.java
com.donnemartin.android.fieldreporter.ReportDatabaseHelper.java
com.donnemartin.android.fieldreporter.ReportFragment.java
com.donnemartin.android.fieldreporter.ReportListActivity.java
com.donnemartin.android.fieldreporter.ReportListFragment.java
com.donnemartin.android.fieldreporter.ReportLoader.java
com.donnemartin.android.fieldreporter.ReportManager.java
com.donnemartin.android.fieldreporter.ReportMapActivity.java
com.donnemartin.android.fieldreporter.ReportMapFragment.java
com.donnemartin.android.fieldreporter.Report.java
com.donnemartin.android.fieldreporter.SQLiteCursorLoader.java
com.donnemartin.android.fieldreporter.SingleFragmentActivity.java
com.donnemartin.android.fieldreporter.TrackingLocationReceiver.java