Book List App

An app that uses the Google Books Api. The network operation is done in a background thread and uses the AsyncTask Class.

screenshot_1505109303

screenshot_1505109288

Video link: https://www.youtube.com/watch?v=nKCMGkxsi2A&index=3&list=PL5BgP53rzYkiixvapGL6PUU2oxhvFaRmR

Inventory App

An app that combines Content Providers and SQLite.

Content providers:

  1. Manage access to a structured set of data
  2. Good abstraction layer between data source & UI code ( can add data validation, can modify how data is stored and UI code is unaffected )
  3. Works well in other Android framework classes
  4. Can easily share data with other apps.

Check this video to see how the app is working.

https://www.youtube.com/watch?v=9EJnvLhVtGE&list=PL5BgP53rzYkiixvapGL6PUU2oxhvFaRmR&index=4

News APP

This app is using, the guardian news api(http://open-platform.theguardian.com/documentation/). The network operation is done in a background thread and uses Loaders.

No matter how many times you request data from a loader, by default the Loader will only fetch data once. Second when an activity shuts down, it will automatically tell all of its Loaders to quit what they are doing, since the data won't be used. Finally, Loaders persist across activity configuration changes like rotations. So if we kick off a Loader to go fetch data and the phone is rotated, the loader will automatically return its data to the new activity when it’s done.

Starting a Loader

Within your activity you can start a Loader with the help of the LoaderManager. Every intro activity comes equipped with a LoaderManager which takes care of creating, reusing, destroying loaders at the appropriate time. Once we get a reference to the LoaderManager, we can now call the initLoader method.

Loader initLoader(int id, Bundle args, LoaderCallbacks callback)

And can be called as

getLoaderManager().initLoader(0 ,null, this);

initLoader() ensures that loader is both initialised and active. It has two possible outcomes:

If the loader with the specified ID already exists, the last created loader is used. Now if the Loader with the ID doesn’t exist, then the LoaderCallback, onCreateLoader() method will be triggered, which should return a new Loader. So when we rotate the device over and over again, the same Loader will be used, instead of creating a new one on each orientation change.

Creating a Loader

So how does the Loader get created? By implementing the LoaderCallbacks interface. Our activity needs to override the following three callback methods in order to interact with the LoaderManager.

onCreateLoader(): When this method is called, we need to create and return a new Loader object which will fetch data from the server.

onLoadFinished(): This method is called when the Loader is finished loading data on the background thread. This is a good place to update the UI with the list of data.

onLoaderReset(): This method gets called when the previous created loader is being reset.

LoaderManager interacts with an activity to manage one or more Loader instances. In order for our Activity to be a client that interacts with the LoaderManager, we need MainActivity to implement the LoaderManager.LoaderCallbacks interface. Then the activity must override the:

onCreateLoader() method to create and return a new Loader instance. onLoadFinished() method to receive the data once the Loader has finished. onLoaderReset() method to handle when the previously created Loader is no longer needed, and the existing data can be discarded.

To start a loader when the app is launched in the MainActivity onCreate() method, we should call getLoaderManager().initLoader(0, null, this).

screenshot_1505107488 screenshot_1505107495