-
-
Save udacityandroid/ee8fe10c04ec2d912c509ee3fb287149 to your computer and use it in GitHub Desktop.
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. | |
} | |
} |
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 | |
} | |
} |
loaderManager.initLoader(EARTHQUAKE_LOADER_ID,null, this).forceLoad();
//this is not valid right now . The ide request callback instead of this .What do I do?
@KyawYe-Htut
use this code in the onCreate method in EarthquakeActivity :
LoaderManager loaderManager = getSupportLoaderManager();
loaderManager.initLoader(1, null, this);
don't use forceLoad() in EarthquakeActivity, use forceLoad() in EarthquakeLoader, ps : sorry my english bad:)
The below things worked for me.
Step -1: Make the changes as in udacity/ud843-QuakeReport@6ac53a7?diff=split
Step -2 : use this code in the onCreate method instead of EarthquakeActivity class :
LoaderManager loaderManager = getLoaderManager();
loaderManager.initLoader(1, null, this);
Step -3: Declare EarthqaukeLoader class as static as given below
public static class EarthquakeLoader extends AsyncTaskLoader<List>
What about LoaderManager.LoaderCallbacks instead of LoaderCallbacks ?
Same
Is there any reason why we made AsynTask an anonymous class of the Earthquake activity but AsyncTaskLoader is its own class?
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
Please make an update for deprecated android class like this Loader lesson.
So do for many other out dated lessons.Thank a lot .