Browse files

Done T0802- AddAsyncTaskToRetrieveCursor

  • Loading branch information...
GinaHsu committed Oct 11, 2017
1 parent b8661b7 commit b3dfde696c7809382f77f0c39f48d4d51837ec8a
@@ -16,11 +16,16 @@
package com.udacity.example.quizexample;
import android.content.ContentResolver;
import android.database.Cursor;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import com.udacity.example.droidtermsprovider.DroidTermsExampleContract;
* Gets the data from the ContentProvider and shows a series of flash cards.
@@ -31,6 +36,8 @@
private int mCurrentState;
// TODO (3) Create an instance variable storing a Cursor called mData
// The data from the DroidTermsExample content provider
private Cursor mData;
private Button mButton;
// This state is when the word definition is hidden and clicking the button will therefore
@@ -51,6 +58,7 @@ protected void onCreate(Bundle savedInstanceState) {
mButton = (Button) findViewById(;
// TODO (5) Create and execute your AsyncTask here
new WordFetchTask().execute();
@@ -95,4 +103,31 @@ public void showDefinition() {
// provider and return the Cursor object
// TODO (4) In the onPostExecute method, store the Cursor object in mData
// Use an async task to do the data fetch off of the mail thread
public class WordFetchTask extends AsyncTask<Void, Void, Cursor>{
// Invoked on a background thread
protected Cursor doInBackground(Void... params) {
//Make the query to get the data
//Get the content resolver
ContentResolver resolver = getContentResolver();
//Call the query method on the resolver with the correct Uri from the contract class
Cursor cursor = resolver.query(DroidTermsExampleContract.CONTENT_URI,
null, null, null, null);
return cursor;
//Invoked on UI thread
protected void onPostExecute(Cursor cursor) {
mData = cursor;

0 comments on commit b3dfde6

Please sign in to comment.