NOTE:

NOTE: Of late, I have been getting requests for very trivial problems that many of you are facing in your day-to-day work. This blog is not to solve your "project" problems - surely not a "Support" site.
I just love to share my knowledge in my spare time and would appreciate any questions or feedback on the articles and code I have shared. I also do appreciate thought-provoking questions that would lead me to write more articles and share.
But please do not put your day-to-day trivial problems here. Even if you do, you most probably would not get a response here.
Thanks

Search This Blog

x

Wednesday, 26 August 2009

Fundamentals | Android Tutorial for Beginners (Part 1)

This is Part 1 of a series of articles I plan to write to simplify the new paradigms introduced by the Android platform for developers.
The part 1 will only define and introduce the fundamental building blocks of Android. Later articles will provide sample code focusing on one aspect at a time, more to drive home to concept than to show any great programming skills.


From a developer's perspective, the fundamental building blocks / components of Android are:
1. Activities
2. Services
3. Broadcast Receivers
4. Content Providers.


The means of communication between the above mentioned components is through
1. Intents
2. Intent Filters


The User Interface elements are by using what are called:
1. Views
2. Notifications


Now, having broadly classified the basics, I would like to give a simple definition for each of them, before we can appreciate the need for each of them.


Activity is the basic building block of every visible android application. It provides the means to render a UI. Every screen in an application is an activity by itself. Though they work together to present an application sequence, each activity is an independent entity.


Service is another building block of android applications which does not provide a UI. It is a program that can run in the background for an indefinite period.


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


Content Providers are a separate league of components that expose a specific set of data to applications.


While the understanding and knowledge of these four components is good enough to start development, the knowledge of the means of communication between the components is also essential. The platform designers have introduced a new conpect of communication through intents and intent filters.


Intents are messages that are passed between components. So, is it equivalent to parameters passed to API calls? Yes, it is close to that. However, the fundamental differences between API calls and intents' way of invoking components is
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.


NOTE: Intents can be made to work exactly like API calls by using what are called explicit intents, which will be explained later. But more often than not, implicit intents are the way to go and that is what is explained here.



One component that wants to invoke another has to only express its' "intent" to do a job. And any other component that exists and has claimed that it can do such a job through "intent-filters", is invoked by the android platform to accomplish the job. This means, both the components are not aware of each other's existence and can still work together to give the desired result for the end-user.


This dotted line connection between components is achieved through the combination of intents, intent-filters and the android platform.


This leads to huge possibilities like:
1. Mix and match or rather plug and play of components at runtime
2. Replacing the inbuilt android applications with custom developed applications
3. Component level reuse within and across applications
4. Service orientation to the most granular level, if I may say


Now that the concept of intent has been introduced, let me get down to a more formal definition of Intent.


Intent is a bundle of information, a passive data structure that holds an abstract description of the operation to be performed. (or in the case of broadcasts, a description of an event that has happened and is being announced).


There are 2 types of intents which I intend to detail in the next part of this series. Before winding up part 1, I would finally also give you a formal definition of Intent filters.


Intent filters are the means through which a component advertizes its own capabilities to handle specific job/operations to the android platform.


112 comments:

  1. Nice tutorial, your all tutorials a re really good, keep the good work going...

    ReplyDelete
  2. Hi, I'm an Admin for a popular Sony Ericsson based forum and blog at www.se-nse.net.

    Currently we're looking to expand to cover Android and are looking to invite people with good Android development knowledge to join the forum. Furthermore we would like to develop an Android application for se-nse.net through a community based project.

    Your Android tutorials are excellent and I'd like to invite you over to the forum to join our growing community and perhaps become a member of the new "Developers" group who will have a private forum section for software development and of course be able to contribute to the creation of a se-nse.net app for Android.

    Please head over to the site and take a look, there's a little more info about the developer recruitment in this topic.

    Many thanks and I hope to see you on the forum,

    Mik

    ReplyDelete
  3. Hi Sai,

    my apologies for posting this here but there was no post directly relating to my problem. The problem is described below and I thought you may have some ideas to help me out. Thanks a lot in advance.

    When I make a call to the readLine() method of BufferedReader within a thread handler my application hangs up indefinitely. The problem occurs in the line " fromServer = in.readLine();" in bold within the handleMessage() method in the code snippet below. When I remove calls to the Bufferedreader methods the thread executes properly without problems. I could also send the eclipse project file if you wish.

    Any help will be appreciated. Thanks very much in advance.


    public class TCPClient implements Runnable {


    Handler myHandler2 = new Handler(){
    public void handleMessage (Message m)
    {
    switch (m.what)
    {
    case 2:
    try {
    fromServer = in.readLine();
    if (fromServer.equals("Bye."))
    {
    try
    {
    closeAllConnections();
    }catch (IOException e){

    }
    }

    if (fromUser != null)
    {
    out.println(fromUser);
    fromUser = null;
    }
    } catch (IOException e) {
    fromServer = "Okokoko";
    }

    break;
    default:
    break;
    }
    super.handleMessage(m);

    }

    }

    };

    public void run() {


    while (!Thread.currentThread().isInterrupted()){
    try{
    Thread.sleep(150);

    }catch (InterruptedException e){
    Thread.currentThread().interrupt();
    }
    Message m2 = new Message();
    m2.what = 2;
    myHandler2.sendMessage(m2);
    }
    }

    public static String obtainNewText() {
    if (fromServer != null)
    {
    return fromServer;
    }
    else return "No Data!";
    }

    public static void sendNewText(String s) {
    fromUser = s;
    }


    }

    ReplyDelete
  4. Hi Osagie,

    Has your problem been solved? If not, it would be great if you can share your complete project for me to execute and help you.
    -Sai

    ReplyDelete
  5. This comment has been removed by the author.

    ReplyDelete
  6. Hi Sai,

    thanks a lot for your response. I finally found the reason for the problem. the reason is that the readLine() (in.readline() ) method blocks until a new line is received. All I needed to do was use in.ready() to check if a new line was available before calling readLine().

    Regards,
    Osagie

    ReplyDelete
  7. Hi Sai Geetha... your tutorials are simply superb and useful. Could you please explain about the IVR system in android and how to implement the IVR in android.please provide the step by step procedure. thanks

    ReplyDelete
  8. Hi Saravana,

    Thanks for the compliment. :) I did not get your question on IVR. I do not see any native libraries that provide any support for IVR in Android. Can you please elaborate your question?

    ReplyDelete
  9. Your tutorials are really encouraging and helpful to the people who are new to android like me.My sug is please provide sample codes to the basics such that they should be understand by new comers...

    ReplyDelete
  10. 1. IS IVR possible in android ?

    2. If yes means please post the tutorial.

    ReplyDelete
  11. Sai Geetha,
    Thank you for great work. Your tutorials are a great help for android newbie like me.

    ReplyDelete
  12. Hi Sai,

    Really Nice tutorial. Its very helpful for a beginner like me..

    I have a problem. I want to create an application which has a book in epub format with audio to it.

    and then want to port this application to fbreaderj.

    Can you suggest me how can this be achieved ?

    Sorry for posting me problem here..

    Thanks in advance..

    ReplyDelete
  13. Hi Sai,
    I am trying to construct a dice rolling program with the following parameters.
    User can choose how many dice they want (1 to 6) and how many faces the die has (1 to 26). I have the view that I want and am trying to implement this using EditText for user input, but have no idea how to grab the input and process it. I'm very new to Android and have a little Java experience. If anyone has a skeleton code or could help it would be greatly appreciated.

    ReplyDelete
  14. Bravo!!!

    Simple put... excellent as usual...

    ReplyDelete
  15. Hi Geetha,

    great work! Thanks.

    How to contact you?

    Would you pls kindly approve LinkedIn request?

    Thanks & Best regards
    kaanthan

    ReplyDelete
  16. Hey, I bought the iPhone version and left a snarky comment for Apple :-). Package it for Android and I'm there on my Nexus One. I love this game.

    ReplyDelete
  17. Hi Sai,

    my apologies for posting this here but there was no post directly relating to my problem. I thought you may have some ideas to help me out. Thanks a lot in advance.

    I purchased the M002 android tablet(android version 1.6), in that i am able to properly play the full size video using the video view where as when i reduced the video view size then video is not playing properly the same operations i did in emulator it is working properly means video is playing properly in both cases.

    Thanks in advance

    Please help me to solve my problem.

    ReplyDelete
  18. Hi, Can we use your articles with credits to you? Please approve.

    ReplyDelete
  19. Hi Admin,

    Where do you want to use my articles? In another site? or a printed publication?

    ReplyDelete
  20. Hi This one is nice tutorial for ours(Beginers)

    ReplyDelete
  21. Nice tutorial...., All the Best...

    ReplyDelete
  22. Is it possible to use one application in another one? if it is, can you give any example with explanation??How to achieve that?

    ReplyDelete
  23. Hello .. Your tutorials are excellent. Do u have a tutorial on how to make Favorites button in android applications. I am working on a project that needs it and your help would be very useful.

    ReplyDelete
  24. Hi Sai Geetha,

    Your posts are really helpful. We are developing android application for our 8th Sem project. We are using your blog as our reference. :)

    ReplyDelete
  25. hi...am swathi..
    really this is a nice tutorial to know about basics briefly....
    good one

    thankq

    ReplyDelete
  26. hai can u plz help me?
    i had two packages pkg 1 and pkg2 .
    how can i call anctivity in pkg2 from an activity in pkg1?
    plz plz help me im really in trouble

    ReplyDelete
  27. Very nice introduction. Thank you very much!

    ReplyDelete
  28. Hi iam Raju
    nice article regarding basics...

    ReplyDelete
  29. Hi

    I need complete detail of Activities,intents,Intentfilters,android maifest file,calling one event from other event could you please any one can send me a details
    manjupradee@gmail.com

    ReplyDelete
  30. Hi Geetha,

    Thak you for your excellent Android blog.
    i am a new to android,could you please help in finding good example for accessing internet/webpage data and displaying it on android application.i searched a lot but didnt seen a good one....

    ReplyDelete
  31. Hi
    Superb tutorial.
    I am newbie to this android.could you please explain the android components with an example and also how service and broadcast receivers are interconnected.

    ReplyDelete
  32. Hi SaiGeetha,
    hope we are doing good,
    i am working in mobile based company.
    i want to learn android development.please advise me
    i have to learn basic level.
    please help me like (material,blogs,books)

    --Srinivasn

    ReplyDelete
  33. can u just help me out ......
    I just want to know how to read the album art or cover art of any media file>>

    ReplyDelete
  34. hi sai geetha,
    hope we are doing well.

    page views will reaches 200000 today

    ReplyDelete
  35. keep it up.....

    ReplyDelete
  36. Good work, thx for your Android blog.

    ReplyDelete
  37. I have been following your blog since my early days.I have 1 year and 6 months of experience on Android.All of my experience has been into application development.Recently I have got offers from two companies..One is offering me a profile to work on application layer and other is offering a profile on android middleware.Can you guide me which would be better.Is middleware development better than application layer development from the career perspective in terms of money and other opportunities.

    ReplyDelete
  38. The main thing is that the text which i entered into the edittext is added to the list view .It is added but in some other language not in english what is the problem in this.Please explain

    ReplyDelete
  39. hello mam,
    i have some problem in my spinner allication .
    it doesn.t work with my app.I have tried many times. but there is a
    Warning
    Tue May 31 11:53:03 IST 2011
    AndroidManifest: Ignoring unknown 'string-arrayplanet_array' XML element
    ?
    please help me to overcome this problem .

    ReplyDelete
  40. Hii Geeta,
    I am a great fan of yours and your articles.
    I am an android developer and now i am doing a cricketInfo apps for myself.i am parsing RSS feeds(espn cricket link) and getting a listview which is showing an another url by which i am getting the score card web view.

    But my question is "How can i get Individual score of players?" I want to use that particular score and want to give broadcast message in every given time by user..

    Please help me.
    I will be greatfull to you.

    My email id: mnj.behera1@gmail.com

    ReplyDelete
  41. Hi Geeta,
    I read some of ur articles.Its fentastic.Thank you for providing information in blogs..

    I have one small question. Can we convert lower version to higher version.
    I developed an Map app in 2.3.1 but it is not working in 2.2 version.can i convert it into 2.2 . how........
    please solve my problem........
    my email id is sireesh241@gmail.com
    Thank you.........

    ReplyDelete
  42. Hi Geeth,

    one help

    how to compare web service date to calendar date in android ?then i want to highlight that date in my calendar...how to achieve this one?give me some idea.. please reply to this mail id iamvijayakumar@gmail.com

    ReplyDelete
  43. Hi,


    Great tutorial for android beginners.

    Give me some code for database add,edit and delete function.

    Thanks,
    Alexandar Joseph J

    ReplyDelete
  44. Hi Sai-

    Just found your site.
    Thanks so much for putting this together - it's a great resource!

    ReplyDelete
  45. This tutorial is really helpful for me thanks..........

    ReplyDelete
  46. hi..sai geetha gaaru
    your tutorials are very superb

    ReplyDelete
  47. Hi sai geetha,

    Your blog is very good and so helpfull,thanks a lot.I need some help regarding device compatibility.That is my application should be compatable on different devices(screens).So, please help in this scenario.

    Thanking you,
    Nageswarararo.

    ReplyDelete
  48. thanks for providing such a wonderful introduction on android basics.............

    ReplyDelete
  49. hi geeta ji..i like ur blog most .. ur way of explanation is very good.. i got inspiration from you..and i started my own blog for j2me and android...http://masterkissor.blogspot.com/ ..tnx a lot

    ReplyDelete
  50. i like this tutorial...........

    ReplyDelete
  51. Bookmarked this blog. Thanks for sharing your knowledge and experience.

    ReplyDelete
  52. Very nice tutorial.

    ReplyDelete
  53. This comment has been removed by the author.

    ReplyDelete
  54. Thanx a lot!! sai geetha... i want this type of information for Android...such a great Help..

    ReplyDelete
  55. i found another link for superb tutorials

    http://www.jabershabeek.page4.me

    visit to study some basics about android

    ReplyDelete
  56. hi,

    Pl anyone give the solution. How to change the image in listview when seleting.

    ReplyDelete
  57. How to change the image when selecting the listview..

    ReplyDelete
  58. I think most of the peoples are get good knowledge about android, because its having the useful information. so thanks for creating this interesting blog.

    ReplyDelete
  59. hai sai...
    I am new to Android i have a doubt about creating new gallery.. i dont know how move a image from one album to another album

    ReplyDelete
  60. Hi Sai....
    I am new to Android i have a doubt about drawable.... I am trying to store images in only drawable-hdpi the images are stretching automatically in XML File.....I dot know how to solve this can u help me........Thanks

    ReplyDelete
  61. HI sai,
    Iam new learner in Android idon't know how to create sd card,camera

    ReplyDelete
  62. your site's really great articles.I love android ,too

    ReplyDelete
  63. i am doijng a zoom application. So i want to add a bar that we normally see in a zooming app. which can be used to zoom in and out. So plz give me some guidelines to add that bar.

    ReplyDelete
  64. hi.
    explain json

    ReplyDelete
  65. Hi Sai,
    Plz explain web services in android..?

    ReplyDelete
  66. Hi This is very useful for me basics for androids. I need a concept of taking images to pdf .and the pdf will be stored images. If any body Plz Help me..

    ReplyDelete
  67. This is one of the awesome and good post..I like your blog tips.thanks for your support.good work.

    ReplyDelete
  68. It's very useful to android beginners

    ReplyDelete
  69. I am admin at mobilespecz.net.I love your blog.I came here looking for android tutorials and what you have done here is awesome.Great work madam.

    ReplyDelete
  70. Very helpful....great work mam...

    ReplyDelete
  71. I have been a mobile developer for over 7 years on J2ME and Blackberry platforms and now that I wanted to get into Android, I just happen to find this tutorial on the way to find an online guide for beginners.. and I must say, I wouldn't have found a better guide to start with..

    Absolutely simplest way to explain the best information on Android for very beginners.

    Thanks,
    Nanda K.

    ReplyDelete
  72. Brief and excellent Guide!

    ReplyDelete
  73. hi Geeta,

    Really good notes for begginers,,,,, Thanks J.

    ReplyDelete
    Replies
    1. hi sai geetha i found very good material in this site.. thanks a lot..

      Delete
  74. Dear Geetha

    Me frm bngl I jst nw read your article.It's amazing I am rookie in android
    and I like to know

    Difference between a service and a thread

    ReplyDelete
    Replies
    1. Excellent article on Android Apps Development, This tutorial is very help full for me.

      Delete
  75. Rize is providing Android Apps Development services from long time, fell free to contact us at any moment.

    ReplyDelete
  76. Thank you very much. Bookmarked.

    ReplyDelete
    Replies
    1. really nice tutorial, thanks Geetha.

      Delete
  77. I would be supportive on all of your articles and blogs because they are just upto the mark.
    useful source

    ReplyDelete
  78. Nice tutorial. Well researched & explained. Thanks for sharing.

    Android Application Development.

    ReplyDelete
  79. Excellent introduction to Android. It is very clear and succinct. Thanks, Geetha.
    pudojava.

    ReplyDelete
  80. Nice tutorial, your all tutorials a re really good, keep the good work going.

    ReplyDelete
  81. This comment has been removed by a blog administrator.

    ReplyDelete
  82. sir,
    am a beginner and i want to create an app which could take some data and send that data to mysql database in between i used php page to send that data through insert query to mysql, but i dont know why it is not connecting,and if am sending direct data through browser using php page so its working but why not with Android App plz tell me sir i have to complete my major project soon..

    ReplyDelete
  83. Can anyone kindly give some info on how to create mashup by using the camera and android's location services?




    ReplyDelete
  84. Hi Saigeetha,
    I am rajasekhar,Hyderabad,
    I want to learn android... i dont know any programming languages also,
    could you please suggest me how can i learn?
    i read 1st chapter from this tutorial some technical words are there...
    is it sufficient? or before learning android i have to learn any languages?
    Please suggest me...
    Thanks

    ReplyDelete
  85. Hi Sai Geetha,

    Nice Introduction to Android Programming. Helped me a lot to understand what is Android Programming all about !!!
    Thanks

    ReplyDelete
  86. Hi,Sai Geetha,
    your Introduction was good. i want to learn Android .Kindly please help me total notes which useful for learning Android . Iam waiting for your response

    ReplyDelete
  87. Check this quiz that found interesting .

    Android Fundamentals Quiz

    ReplyDelete
  88. Thank you so much sai geetham
    Recently i've moved to android development i was fully confused by the docs provided by google. Your articles really helping me :)

    ReplyDelete
  89. can you guide me to leran brief about he basics in android

    ReplyDelete
  90. Hi geetha i want to calculate an speed of the object in the camera recording . how to find can u help.

    ReplyDelete
  91. Sai,

    I just happened to stumble upon your blog and found to my total surprise found out what I was looking for. A nice tutorial.

    Thanks

    ReplyDelete
  92. This comment has been removed by a blog administrator.

    ReplyDelete
  93. Hai, Your Doing Great, I made fan of your Blog. Can You share Simple Tutorials Related Some Main Android Topics.

    ReplyDelete
  94. This comment has been removed by a blog administrator.

    ReplyDelete