Android Open Source - android Parse All Chefs Task

From Project

Back to project page android.


The source code is released under:

Apache License

If you think the Android project android 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

//from w w w. ja v a  2  s. co m
import android.content.Context;
import android.os.AsyncTask;
import android.os.Handler;

import com.parse.ParseException;
import com.parse.ParseObject;
import com.parse.ParseQuery;

import java.util.LinkedList;
import java.util.List;

 * Task which queries parse for a list of all the chefs we are currently
 * storing.
 * <p/>
 * This shouldn't be called by the presentation layer. Its best if
 * Created by mike on 7/11/14.
public class ParseAllChefsTask extends AsyncTask<Void, Void, Void> {

    private Context context;
    private OnParticipantQueryListener<Chef> listener;

    public ParseAllChefsTask(Context context, OnParticipantQueryListener<Chef> listener) {
        this.context = context;
        this.listener = listener;

    protected Void doInBackground(Void... params) {
        Logger.log(ParseAllChefsTask.class, "Starting background download of all chefs from Parse");

        // Create a parse query for the entire chefs table
        ParseQuery<ParseObject> query = ParseQuery.getQuery(ParseID.CLASS_CHEF);

        // Execute the query
        List<ParseObject> queryResult = null;
        try {
            queryResult = query.find();

        } catch (ParseException e) {
            Logger.err(ParseAllChefsTask.class, "An error was thrown during a Parse query for all chefs", e);

            if (listener != null) {
            return null;

        // Convert each parse object into our own Chef data model
        List<Chef> chefs = new LinkedList<Chef>();
        for (ParseObject pObject : queryResult) {

        // Alert the listener
        if (listener != null) {

        return null;

     * Alerts the listener on the UI thread that execution has completed
    private void alert(final List<Chef> chefs) {
        if (listener == null) {

        Handler handler = new Handler(context.getMainLooper()); Runnable() {
            public void run() {



Java Source Code List