+ All Categories
Home > Documents > Android Fundamentals and Components _ Techblogon

Android Fundamentals and Components _ Techblogon

Date post: 06-Jul-2018
Category:
Upload: vairamoorthy-arunachalam
View: 230 times
Download: 0 times
Share this document with a friend

of 13

Transcript
  • 8/18/2019 Android Fundamentals and Components _ Techblogon

    1/13

    Home

    About us

    Contact us

    Privacy Policy

    Tutorials »

    Gadgets »

    Internet »

    Technologies »

    Android Fundamentals and Components

    January 27, 2013 Android Tutorial, Tutorials

    Android Fundamentals and Components

    Before going to start development, we need to know about Android Fundamentals and Components, which we

    will use frequently while developing our android applications. From a developer’s perspective, some important

     building blocks / components of android are as bellow. Just have a look at them for now, we will discuss them in

    details latter on.

    1. Activities

    2. Services

    3. Broadcast Receivers

    4. Content Providers

    When we are developing application, always we will have some requirements like, passing messages within an

    application (one screen to another) or between different applications.

    For example: Let’s say a new message came to your phone, so we update the notification bar for that new

    message. So we will have to pass the information from message application to notification bar. Moral of the story

    is, the means of communication between the above mentioned components is through the bellow components.

    1.Intents

    http://techblogon.com/category/technologieshttp://techblogon.com/category/tutorials/http://techblogon.com/https://twitter.com/techblogonhttp://www.facebook.com/Techblogonhttp://gplus.to/techblogonhttp://techblogon.com/?feed=rss2http://techblogon.com/privacy-policy/http://techblogon.com/https://twitter.com/techblogonhttp://techblogon.com/category/technologieshttp://techblogon.com/http://techblogon.com/contact-us/http://techblogon.com/category/tutorials/http://techblogon.com/?feed=rss2http://gplus.to/techblogonmailto:[email protected]://techblogon.com/category/tutorials/http://techblogon.com/http://techblogon.com/category/tutorials/android-tutorial/http://techblogon.com/category/gadgetshttp://techblogon.com/about-us/http://techblogon.com/privacy-policy/http://www.facebook.com/Techblogonhttp://techblogon.com/category/internet

  • 8/18/2019 Android Fundamentals and Components _ Techblogon

    2/13

    2. Intent Filters

    Let’s come to the GUI part. The User Interface elements are made up the below components, which we called:

    1. Views

    2. Notifications

     Now it is time to describe in details for each of the above components and its requirement and usages.

    Android Activity

    Activity is the basic building block of every visible android application. It provides the means to render a GUI.

    Every screen in an application is an activity by itself. We can call each visible component as an activity in

    android. Though more than one activities work together to present an application sequence, each activity is an

    independent entity. Just have a look at the below image, which explains the life cycle of an activity. I will explain

    the practical use of an activity, when we will develop our first “Hello World” application in this tutorial.

    Life Cycle of an Activity in Android

  • 8/18/2019 Android Fundamentals and Components _ Techblogon

    3/13

    To make you understand the real usage click here for complete example.

    Android Services

    Service is another building block of android applications which does not provide any UI. It is a program that can

    run in the background for an indefinite period. That means if we want to do a long operation (example: download

    data from internet), then we need to create an Android service for this purpose.

    Android Services are little bit confusing. Before going to know What is Android Service? Lets have a clear 

    http://techblogon.com/android-activity-lifecycle-example-code-description/http://techblogon.com/android-fundamentals-components-activity-service-broadcast-receiver-content-provider/lifecycle_of_an_activity/

  • 8/18/2019 Android Fundamentals and Components _ Techblogon

    4/13

     picture in our mind that, What Android Service is not?

    Please keep in mind that , Android Service is neither a separate process nor a thread. Then what exactly it is?

    Using Android Service, we just inform the Android OS that, We are going to do a background

     processing.

    Also Android Service exposes some functionality to other applications using the bind mechanism.

    Generally Android Service are of 2 types.

    Started Service (Unbounded)

    This type of service is created and called by Android Activities. There is no 2 way communication between

    Android Activity and Service. The Activity just starts the service and does not care about the status of the

    service. The Service will finish it’s work and automatically stops when finish it’s job.

    Bound Service (Bounded)

    This type of Android Service is for 2 way communication. Suppose an Android Activity has started a bounded

    service, then Activity can be notified about the status by the service.

    Don’t worry we will discuss in details about Android Services with an example in the example section.

    LifeCycle of a Service in Android

  • 8/18/2019 Android Fundamentals and Components _ Techblogon

    5/13

    To make you understand the real usage click here for complete example.

    Android Broadcast Receivers

    Broadcast Receiver is yet another type of component that can receive and respond to any broadcast

    announcements.

    Let’s take an example; when a new message comes to your inbox, this information will be broadcasted for other 

    applications. If any application wants to do something while a new message comes to your inbox, then it can

    receive the broadcasted message details (Like: sender’s number, content etc.) and process accordingly. Your 

    application must be registered to that receiver to receive the broadcasted message.

    Android Content Providers

    Content Providers are a separate league of components that exposes a specific set of data to applications. Let’s

    take an example: If you want to search a contact in your contact database (Like: name, number etc), then you

    can use Content Provider for this purpose. You can say Content provider is the pointer in your application which

     points to a specific database from other application.

    http://techblogon.com/android-fundamentals-components-activity-service-broadcast-receiver-content-provider/life-cycle-of-an-service/http://techblogon.com/simple-android-service-example-code-description-start-stop-service/

  • 8/18/2019 Android Fundamentals and Components _ Techblogon

    6/13

    I think the basic knowledge of these four components is good enough to start development now, the knowledge

    of the means of communication between the components is also essential. So the android platform offers a new

    concept of communication through intents and intent filters.

    To make you understand the real usage click here for complete example.

    Android Intents

    Intents are messages that are passed between components. So we have a question in our mind. Is it equivalent to

     parameters passed to API calls? Yes, it is close to that. However, the fundamental differences between API call

    and intents is the way of invoking it. Lets have a look at the difference between these two in below points.

    1. API calls are synchronous while intent-based invocation is asynchronous (mostly)

    2. API calls are bound at compile time while intent-based calls are run-time bound (mostly)

    It is these two differences that take Android platform to a different league.

    In simple word, the core android components of an application — activities, services, and broadcast receivers

     — are activated through messages, called intents.

    For example an activity can send an intent  to the Android system which starts another activity. So an Intent is

     just a way to send a message in android.

    Android intents are basically 2 types in nature.

    1. Implicit Intents

    Implicit intents specify the action which should be performed by other components or applications.

    https://twitter.com/intent/user?original_referer=http%3A%2F%2Ftechblogon.com%2Fandroid-fundamentals-components-activity-service-broadcast-receiver-content-provider%2F&region=count_link&screen_name=techblogon&tw_p=followbuttonhttps://twitter.com/intent/follow?original_referer=http%3A%2F%2Ftechblogon.com%2Fandroid-fundamentals-components-activity-service-broadcast-receiver-content-provider%2F&region=follow_link&screen_name=techblogon&tw_p=followbuttonhttp://techblogon.com/android-fundamentals-components-activity-service-broadcast-receiver-content-provider/content-provider-in-android/https://plus.google.com/+Techblogon?prsrc=5http://techblogon.com/sample-code-listview-sqlite-database-connection-in-android/

  • 8/18/2019 Android Fundamentals and Components _ Techblogon

    7/13

    For Example: If you want to open an URL in a web browser from your application code, Then following code

    tells the Android system how to view a webpage. Typically the web browser is registered to this Intent but

    other component could also register themselfs to this intent. That means if you have installed web browsers like

     IE, Mozilla Firfox and Google Chrome, then all browsers might be registered to the intent

    (Intent.ACTION_VIEW) to show a web page as per you request.

    If only one component (here web browser in our example) is found, Android starts this component directly. If 

    several components are identifier by the Android system, the user will get an selection dialog and can decide

    which component should be used for that Intent.

    2. Explicit Intents

    Explicit intents explicitly defines the exact component which should be called by the Android system, by using the

    Java class are identifier.

    The following code shows how to create an explicit intents and send it to the Android system. That means

    Android system will directly execute your intent request as you requested. Explicit intents are typically used

    within an application, as the classes in an application are controlled by the application developer. If you want to

    open an Android Activity from another activity, then below is the code for it using an intent to do so. Also you

    can send some data to that activity if required.

    Android Intent Filters

    To inform the system which implicit intents they can handle, activities, services, and broadcast receivers can have

    one or more intent filters. Each filter describes a capability of that component, a set of intents that the component

    is willing to receive.

    Let’s take an Example: The ‘NotePadEditor’ activity of the sample Note Pad application has two filters — one

    for starting up with a specific note that the user can view or edit, and another for starting with a new, blank note

    that the user can fill in and save.

    Basically IntentFilters are defined in the AndroidManifest.xml file. For BroadcastReceiver it is possible to defineit in our code itself. An IntentFilters is defined by its category, action and data filters. It can also contain

    additional metadata. If a component does not define an Intent filter, then it can only be called by explicit Intents.

    To make you understand the real usage click here for complete example.

     Previous Page

     Android Tutorial Home Page

    12

    Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.techblogon.com"));startActivity(i);

    123

    Intent i = new Intent(this, ActivityTwo.class);i.putExtra("First Value", "This First Value for ActivityTwo");i.putExtra("Second Value", "This Second Value ActivityTwo");

    http://techblogon.com/android-development-tutorial-for-beginners/http://techblogon.com/android-intent-example-code-description/http://techblogon.com/install-eclipse-android-sdk-adt-pluin/

  • 8/18/2019 Android Fundamentals and Components _ Techblogon

    8/13

    Post By SmrutiRanjan (57 Posts)Working @ Samsung as a P roject Lead for AndroidSmartphones. I have been blogging since 2008.Previously I was w riting articles for other bloggers, butfinally I have started my own blog-"Techblogon".I am alsoan active contributor for the blog-"Gadgets n Gizmos

    World". Job is my necessity, but blogging is my pass ion.

    Website: → Techblogon

    CONNECT

     Next Page

    Activity in android, broadcast receiver in android, content provider in android, intent filter in android, intent in

    android, notification in android, Service in android, views in android

    15 Responses to Android Fundamentals and Components

    1. Gagandeep Singh says:

    March 19, 2013 at 9:48 am

    awesome… !!!

    Reply

    2.  Dharmendra kumayu says:

    March 26, 2013 at 8:19 am

    it’s really good!

    Reply

    3.  Abinash says:

    March 29, 2013 at 12:22 pm

    I am new to android development… though i have 4.5 years experience in .net technologies…..i find this

    man named SmrutiRanjan is really a great guy…its really very easy to understand..thank bro….

    Cheears

    Abinash Routray

    Reply

    4.  Manish Agarwal  says:

    April 4, 2013 at 5:47 pm

    Hey there.

    I am totally new to app development and don’t know a thing about API.

    Should I first learn something about API to continue with your tutorials?

    http://techblogon.com/android-fundamentals-components-activity-service-broadcast-receiver-content-provider/?replytocom=312#respondhttp://techblogon.com/tag/content-provider-in-android/http://techblogon.com/tag/activity-in-android/http://techblogon.com/android-fundamentals-components-activity-service-broadcast-receiver-content-provider/?replytocom=279#respondhttp://techblogon.com/android-fundamentals-components-activity-service-broadcast-receiver-content-provider/?replytocom=220#respondhttp://in.linkedin.com/pub/smruti-ranjan-nayak/62/ba9/52bhttp://techblogon.com/tag/intent-filter-in-android/http://techblogon.com/tag/service-in-android/https://plus.google.com/u/0/110318797292853934829/postshttp://techblogon.com/tag/broadcast-receiver-in-android/http://techblogon.com/tag/views-in-android/http://techblogon.com/author/smrutiranjan/http://www.facebook.com/smrutiranjantechieshttp://twitter.com/twit2smrutihttp://techblogon.com/http://techblogon.com/tag/notification-in-android/http://techblogon.com/tag/intent-in-android/http://techblogon.com/hello-world-program-applicationin-android/

  • 8/18/2019 Android Fundamentals and Components _ Techblogon

    9/13

    If yes, may you kindly provide to some good articles or tutorials about the same?

    Reply

     SmrutiRanjan says:

    April 5, 2013 at 5:28 am

    Dear Manish,

    API are just the collection of Android functions, Which has already exist with the default Android

    SDK. We just need to call them in our application, so don’t worry.

    Reply

    5.  P.S.Sanatan says:

    April 12, 2013 at 7:13 am

    i came across your blog and i think you can help me.I don’t know about java programming and i have

     basic idea about the c and c++.Then what should be the procedure for me to learn the anroid application

    development.Please guide me…Thank you

    Reply

     SmrutiRanjan says:

    April 12, 2013 at 10:29 am

    Dear Sanatan,

    It is not necessary to know java for android.

    Just setup all android tool, then just learn some common fundamentals like activity, intent, broadcasreceiver etc. then start will hello world program

    You can refer to my site, it is written in such a way that begginers can read from the top to the

     bottom, which will help you to go ahead step by step.

    Reply

      P.S.Sanatan says:

    April 16, 2013 at 10:35 am

    Thank you for your valuable guidance,i am going to do the same thing as told by you andhope you will guide in my way of learning anroid.

    Thank you.

    Reply

    6.  Jones sabo newest charms says:

    April 14, 2013 at 2:09 pm

    Fantastic goods from you, man. I have understand your stuff previous to and you’re just too great.

    http://techblogon.com/http://techblogon.com/android-fundamentals-components-activity-service-broadcast-receiver-content-provider/?replytocom=387#respondhttp://techblogon.com/android-fundamentals-components-activity-service-broadcast-receiver-content-provider/?replytocom=472#respondhttp://techblogon.com/android-fundamentals-components-activity-service-broadcast-receiver-content-provider/?replytocom=436#respondhttp://techblogon.com/android-fundamentals-components-activity-service-broadcast-receiver-content-provider/?replytocom=381#respondhttp://techblogon.com/http://techblogon.com/android-fundamentals-components-activity-service-broadcast-receiver-content-provider/?replytocom=433#respond

  • 8/18/2019 Android Fundamentals and Components _ Techblogon

    10/13

    Reply

    7.  Jones sabo says:

    April 27, 2013 at 4:00 pm

    Some genuinely excellent blog posts on this website , appreciate it for contribution.

    Reply

    8. leela says:

    May 18, 2013 at 6:07 am

    hai sir good morning iam new to Android technology iam learning basics from ur website its really good

    and i want to learn android technology is it good has it future for this technology i want to know please

    give guidance for this and also jobs rating and openings for this technology

    Reply

     SmrutiRanjan says:May 18, 2013 at 6:13 pm

    Very good Android market

    Reply

    9.  Anil SIngh says:

    May 20, 2013 at 4:13 pm

    You are great. I just want to confirm is an activity killed when we press back button on our device?

    Reply

    10.  principally says:

    July 24, 2013 at 9:55 pm

    Awesome things here. I am very glad to peer your article. Thank you a lot and i’m having a look forward

    to contact you. Will you please drop me a mail?

    Reply

    11.  Faisal Goraya says:

    October 29, 2013 at 5:45 pm

    i cannot understand, What is android intents? please explain android intent using simple example?

    Reply

    Leave a Reply

    http://techblogon.com/android-fundamentals-components-activity-service-broadcast-receiver-content-provider/?replytocom=723#respondhttp://techblogon.com/android-fundamentals-components-activity-service-broadcast-receiver-content-provider/?replytocom=1143#respondhttp://techblogon.com/android-fundamentals-components-activity-service-broadcast-receiver-content-provider/?replytocom=463#respondhttp://techblogon.com/android-fundamentals-components-activity-service-broadcast-receiver-content-provider/?replytocom=744#respondhttp://techblogon.com/android-fundamentals-components-activity-service-broadcast-receiver-content-provider/?replytocom=721#respondhttp://techblogon.com/android-fundamentals-components-activity-service-broadcast-receiver-content-provider/?replytocom=1462#respondhttp://techblogon.com/android-fundamentals-components-activity-service-broadcast-receiver-content-provider/?replytocom=544#respondhttp://www.skyline89.info/http://techblogon.com/

  • 8/18/2019 Android Fundamentals and Components _ Techblogon

    11/13

    Your email address will not be published. Required fields are marked *

     Name *

    Email *

    Website

    − 3 = two

    Comment

    You may use these HTML tags and attributes:

    Post Comment

    Search

  • 8/18/2019 Android Fundamentals and Components _ Techblogon

    12/13

    RSS Feed Google Plus

    1,859 people like this. Be the first of your friends.Like

    5

    Follow @techblogon   216 followers

    Enter your Email Address...

    Subscribe

    Archives

    March 2015

    July 2014

    April 2014

    October 2013

    August 2013

    July 2013

    June 2013

    May 2013

    April 2013

    March 2013

    February 2013

    January 2013

    December 2012

    Categories

    Android

    Android Tutorial

    Design Patterns

    Displays

    E-Commerce

    Gadgets

    Google

    Techblogon

    + 305

    Follow +1

    Recommend on Google

    http://techblogon.com/category/gadgets/displays/http://techblogon.com/2013/01/http://feeds.feedburner.com/techblogonhttp://techblogon.com/category/internet/google/http://techblogon.com/2013/04/http://techblogon.com/2015/03/http://techblogon.com/2013/07/http://techblogon.com/2013/03/http://techblogon.com/2013/02/http://techblogon.com/2014/04/http://techblogon.com/category/gadgets/http://techblogon.com/2013/05/http://techblogon.com/category/tutorials/android-tutorial/http://techblogon.com/category/technologies/android/http://techblogon.com/2012/12/http://techblogon.com/2013/08/http://techblogon.com/2014/07/http://plus.google.com/110318797292853934829http://techblogon.com/category/technologies/e-commerce/http://techblogon.com/category/tutorials/design-patterns/http://techblogon.com/2013/06/http://techblogon.com/category/gadgets/displays/http://techblogon.com/2013/10/

  • 8/18/2019 Android Fundamentals and Components _ Techblogon

    13/13

    Internet

    Mobile Phones

    Softwares

    Technologies

    Tutorials

    Windows

    Pages

    About us

    Contact us

    Privacy Policy

    Meta

    Log in

    Entries RSS

    Comments RSS

    WordPress.org

    ©2015 Techblogon

    http://techblogon.com/category/technologies/http://techblogon.com/category/gadgets/mobile-phones/http://techblogon.com/wp-login.phphttp://techblogon.com/about-us/http://techblogon.com/category/technologies/softwares/https://wordpress.org/http://techblogon.com/category/tutorials/http://techblogon.com/comments/feed/http://techblogon.com/contact-us/http://techblogon.com/http://techblogon.com/feed/http://techblogon.com/category/technologies/windows/http://techblogon.com/privacy-policy/http://techblogon.com/category/internet/

Recommended