-
-
Save udacityandroid/ee8fe10c04ec2d912c509ee3fb287149 to your computer and use it in GitHub Desktop.
Switch from AsyncTask to AsyncTaskLoader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class EarthquakeActivity extends AppCompatActivity | |
implements LoaderCallbacks<List<Earthquake>> { | |
... | |
@Override | |
public Loader<List<Earthquake>> onCreateLoader(int i, Bundle bundle) { | |
// TODO: Create a new loader for the given URL | |
} | |
@Override | |
public void onLoadFinished(Loader<List<Earthquake>> loader, List<Earthquake> earthquakes) { | |
// TODO: Update the UI with the result | |
} | |
@Override | |
public void onLoaderReset(Loader<List<Earthquake>> loader) { | |
// TODO: Loader reset, so we can clear out our existing data. | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class EarthquakeLoader extends AsyncTaskLoader<List<Earthquake>> { | |
public EarthquakeLoader(Context context, String url) { | |
super(context); | |
// TODO: Finish implementing this constructor | |
} | |
@Override | |
protected void onStartLoading() { | |
forceLoad(); | |
} | |
@Override | |
public List<Earthquake> loadInBackground() { | |
// TODO: Implement this method | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
so that we don't need to instantiate it for working and making inner class it can access parent class member and function directly,
in loader, we have callback method for establishing a connection that's why prefer to make a new class there