Pages

Tuesday, 30 May 2017

Services

Services

  • A Service is an application component that can perform long-running operations in the background, and it does not provide a UI, and it continues to run in the background even if the user switches to another application
  • In Service, You can override onStartCommand() to allow components to start it and onBind() to allow binding
  • Services are declared in the Manifest file
  • A service runs in the main thread of its hosting process, you should create a new thread within the service to complete operations that take long time to avoid blocking UI thread.

  • The service life cycle for both bound and started services are illustrated in this Google docs diagram

  • Services classes and start modes are illustrated in the following diagram:

*Note: For Intent Service, If you decide to also override other callback methods, such as onCreate(), onStartCommand(), or onDestroy(), be sure to call the super implementation so that the IntentService can properly handle the life of the worker thread.

Reference: https://developer.android.com/guide/components/services.html#Basics

Sunday, 28 May 2017

AsyncTasks


AsyncTasks

  • This class allows you to perform background operations and publish results on the UI thread without having to manipulate threads and/or handlers.

  • The task can be executed only once (an exception will be thrown if a second execution is attempted.)
  • The doInBackground() will continue execution even if the calling activity is destroyed, make sure to call cancel(true) in the activity’s onDestroy(). The task onCancelled() will be called instead of onPostExecute() right after doInBackground() returns
  • Illustration of the basic operations that will be overridden are shown in the following diagram


Reference: https://developer.android.com/reference/android/os/AsyncTask.html


Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License

Purpose of the Blog

I have started learning native android development about a year and half ago, I feel now that summarizing the concepts will help strengthen my knowledge, and help others along the way.