app/src/main/java/com/example/android/quakereport/EarthquakeActivity.java
/**
     * {@link LoaderManager} to perform the network request on a background thread, and then
     * update the UI with the list of earthquakes in the response.
     * <p>
     * AsyncTask has three generic parameters: the input type, a type used for progress updates, and
     * an output type. Our task will take a String URL, and return an Earthquake. We won't do
     * progress updates, so the second generic is just Void.
     * <p>
     * We'll only override two of the methods of AsyncTask: doInBackground() and onPostExecute().
     * The doInBackground() method runs on a background thread, so it can run long-running code
     * (like network activity), without interfering with the responsiveness of the app.
     * Then onPostExecute() is passed the result of doInBackground() method, but runs on the
     * UI thread, so it can use the produced data to update the UI.
     */
LoaderManager to perform the network request on a background thread, and then
update the UI with the list of earthquakes in the response.

AsyncTask has three generic parameters: the input type, a type used for progress updates, and
an output type. Our task will take a String URL, and return an Earthquake. We won't do
progress updates, so the second generic is just Void.

We'll only override two of the methods of AsyncTask: doInBackground() and onPostExecute().
The doInBackground() method runs on a background thread, so it can run long-running code
(like network activity), without interfering with the responsiveness of the app.
Then onPostExecute() is passed the result of doInBackground() method, but runs on the
UI thread, so it can use the produced data to update the UI.
LoaderManager to perform the network request on a background thread and then update the UI with the list of earthquakes in the response . AsyncTask has three generic parameters : the input type a type used for progress updates and an output type . Our task will take a String URL and return an Earthquake . We won ' t do progress updates so the second generic is just Void . We ' ll only override two of the methods of AsyncTask : doInBackground () and onPostExecute () . The doInBackground () method runs on a background thread so it can run long - running code ( like network activity ) without interfering with the responsiveness of the app . Then onPostExecute () is passed the result of doInBackground () method but runs on the UI thread so it can use the produced data to update the UI .
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.earthquake_activity);
        ListView earthquakeListView = (ListView) findViewById(R.id.list);
        mEmptyStateTextView = (TextView)findViewById(R.id.empty_view);
        mAdapter = new EarthQuakeAdapter(this, new ArrayList<EarthQuake>());
        earthquakeListView.setAdapter(mAdapter);
        TextView mEmptyStateTextView = (TextView) findViewById(R.id.empty_view);
        earthquakeListView.setEmptyView(mEmptyStateTextView);
        earthquakeListView.setAdapter(mAdapter);
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
        prefs.registerOnSharedPreferenceChangeListener(this);
        earthquakeListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                EarthQuake currentEarthQuake = mAdapter.getItem(position);
                Uri earthquakeUrl = Uri.parse(currentEarthQuake.getmUrl());
                Intent websiteIntent = new Intent(Intent.ACTION_VIEW, earthquakeUrl);
                startActivity(websiteIntent);
            }
        });
        ConnectivityManager connMgr = (ConnectivityManager)
                getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
        if (networkInfo != null && networkInfo.isConnected()) {
            LoaderManager loaderManager = getLoaderManager();
            loaderManager.initLoader(EARTHQUAKE_LOADER_ID, null, this);
        }
        else {
            View loadingIndicator = findViewById(R.id.loading_indicator);
            loadingIndicator.setVisibility(View.GONE);
            mEmptyStateTextView.setText(R.string.no_internet_connection);
        }
    }
@ Override protected void onCreate ( Bundle savedInstanceState ) { super . onCreate ( savedInstanceState ) ; setContentView ( R . layout . earthquake_activity ) ; ListView earthquakeListView = ( ListView ) findViewById ( R . id . list ) ; mEmptyStateTextView = ( TextView ) findViewById ( R . id . empty_view ) ; mAdapter = new EarthQuakeAdapter ( this , new ArrayList < EarthQuake > ( ) ) ; earthquakeListView . setAdapter ( mAdapter ) ; TextView mEmptyStateTextView = ( TextView ) findViewById ( R . id . empty_view ) ; earthquakeListView . setEmptyView ( mEmptyStateTextView ) ; earthquakeListView . setAdapter ( mAdapter ) ; SharedPreferences prefs = PreferenceManager . getDefaultSharedPreferences ( this ) ; prefs . registerOnSharedPreferenceChangeListener ( this ) ; earthquakeListView . setOnItemClickListener ( new AdapterView . OnItemClickListener ( ) { @ Override public void onItemClick ( AdapterView < ? > parent , View view , int position , long id ) { EarthQuake currentEarthQuake = mAdapter . getItem ( position ) ; Uri earthquakeUrl = Uri . parse ( currentEarthQuake . getmUrl ( ) ) ; Intent websiteIntent = new Intent ( Intent . ACTION_VIEW , earthquakeUrl ) ; startActivity ( websiteIntent ) ; } } ) ; ConnectivityManager connMgr = ( ConnectivityManager ) getSystemService ( Context . CONNECTIVITY_SERVICE ) ; NetworkInfo networkInfo = connMgr . getActiveNetworkInfo ( ) ; if ( networkInfo != null && networkInfo . isConnected ( ) ) { LoaderManager loaderManager = getLoaderManager ( ) ; loaderManager . initLoader ( EARTHQUAKE_LOADER_ID , null , this ) ; } else { View loadingIndicator = findViewById ( R . id . loading_indicator ) ; loadingIndicator . setVisibility ( View . GONE ) ; mEmptyStateTextView . setText ( R . string . no_internet_connection ) ; } }
{@link LoaderManager} to perform the network request on a background thread, and then
 update the UI with the list of earthquakes in the response.
{ @link LoaderManager } to perform the network request on a background thread and then update the UI with the list of earthquakes in the response .
// Set the adapter on the {@link ListView} // so the list can be populated in the user interface // Obtain a reference to the SharedPreferences file for this app // And register to be notified of preference changes // So we know when the user has adjusted the query settings // Get a reference to the ConnectivityManager to check state of network connectivity // Get details on the currently active default data network // If there is a network connection, fetch data // Get a reference to the LoaderManager, in order to interact with loaders. // Initialize the loader. Pass in the int ID constant defined above and pass in null for // the bundle. Pass in this activity for the LoaderCallbacks parameter (which is valid // because this activity implements the LoaderCallbacks interface). // Otherwise, display error // First, hide loading indicator so error message will be visible // Otherwise, display error // First, hide loading indicator so error message will be visible // Update empty state with no connection error message