Friday, 20 December 2013

Android operating System Overview and Activity Life cycle



Before getting started with Android development there are some basic prerequisites that you should be aware of
  1. Object-oriented programming concepts. Android makes heavy use of this.
  2. Some experience with Java.
  3. Experience with Eclipse development Environment.
  4. Basic knowledge of Android.

Android Architecture

  1.  Android runs on top of Linux kernel.
  2. Android uses a virtual machine called Dalvik Virtual Machine . This is specially optimized for mobile devices.
  3. Android has an integrated browser based on open source WebKit engine.
  4. Android has OpenGL ES which is embedded version of OpenGL(2D/3D graphics).
  5.  SQLite database for structured data storage.



Android versions

  1. Cupcake (1.5)
  2. Donut (1.6)
  3. Éclair (2.0/2.1)
  4. Froyo (2.2)
  5. Gingerbread (2.3)
  6. Honeycomb (3.0/3.1/3.2)
  7. Ice Cream sandwich (4.0)
  8. Jelly Bean (4.1/4.2/4.3)
  9. Kitkat (4.4)
  10. Lollipop (5.0/5.0.2)

Application Fundamentals

  1. Applications are written in Java programming language.
  2. You compile applications into Android package file(.apk files) which you can then distribute.
  3. Each application run in its own sandbox protected and isolated from other. They also run in their own Linux process.
  4.  Application consists of Components, a Manifest file and resources.

Android Components

  1.  Activities
    1.  Represents a single screen with a user interface.
    2. An application consists of multiple Activities.
    3. When new Activity starts, the old one is pushed onto stack which user can navigate by pressing back key.
    4. Can be built with xml files or directly by Java.
  2. Services
    1. Used to perform long running operations in the background.
    2. No interface.
    3. For example playing music. No matter what you are doing music keeps playing once started.
    4. Can be bound to other application.
  3. Content Providers
    1. Used to store and retrieve data and make it accessible to all the devices.
    2. By default there is no way to share data across different applications.
    3. Exposes public URI to others application.
    4. Uses database model.
    5. Example Contacts, Media etc.
  4. Broadcast receivers
    1. Responds to system wide broadcast announcements
    2. Example when screen turns off Android sends broadcast which your application can listen to. Other example is when battery gets low.
    3. You can also broadcast your own messages which other applications can listen to.
    4. No user interface though they can be used to create status bar notifications.

    Android Manifest File

    1.  Name must be AndroidManifest.xml and must be in Applications root directory.
    2. Gives Android System information about the Application.
    3. Describes components(mentioned above like Activities) used in Application.
    4. Declares permission required to run the application. If you must have notices when you try to install any app from the market store you have to give some permissions. These are given here.
    5. Declares minimum API level. If this is set only people with Android running version more than the API level will be able to view the application on the app store.

    Android Lifecycle

     

     

Android Lifecycle Methods

 
  •  onCreate() :This methods is called when activity is created.
    • First call will be to super.onCreate() so that android will do some of it's own initializations.
    • You can set the activity's content view by calling method setContentView().
    • You can get references to various UI components like EditText, Button etc by calling findViewById() method and then attach various listeners to it. Eg you can set onClickListener for button.
  •  onRestart() : This  method will be called when activity is stopped and is about to start again. If there is any logic that you need to execute on activity restart you should add it here.
  • onStart() : [Visible only behavior] This method is  called when the activity is about to start. In this method you should typically add logic to load persistent application state like reading from database.
  • onResume() : [Foreground only behavior ] This method is called when activity is visible  and is about to start interacting with the user. In this method you should do tasks related to activity coming to foreground. For eg. Starting a playback music or starting some animation etc.
  • onPause() :  Opposite of onRsume(). This method is called when activity is about to loose focus. In this method you should do things like stopping animation or stopping playback music... handle things you started in onResume() method. You should also save any data that you need to persist like storing user entered data in database.
  • onStop() :  This is when activity is no longer visible to the user. In this method you should typically cache your activity state in case activity is killed and needs is restarted later.
    • Note : If activity is killed by Android OS then onStop() is not called. So saving any persistent data should be done in onPause() method.
  •  onDestroy() : This method is called when activity is about to be destroyed.  Typical things to do here is release resource hold by your application.
    • Note : Again if activity is killed by Android OS then onDestroy() is not called. So saving any persistent data should be done in onPause() method.


Related Links

No comments:

Post a comment

t> UA-39527780-1 back to top