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

Loading...
x

Wednesday, 26 August 2009

Explicit Intent | Android Tutorial for Beginners (Part 2)

Having introduced you to the basic anatomy of an android application in the Part 1 of the series, I would like to show you an example where communication between 2 activities happens through an intent.


However, just one more detail to be introduced as promised and that is -
There are 2 types of intents that Android understands.
1. Explicit Intent
2. Implicit Intent


In an Explicit intent, you actually specify the activity that is required to respond to the intent. In other words, you explicitly designate the target component. This is typically used for application internal messages.


In an Implicit intent (the main power of the android design), you just declare an intent and leave it to the platform to find an activity that can respond to the intent. Here, you do not declare the target component and hence is typically used for activating components of other applications seamlessly
Note: Here for simplicity sake I tell an activity responds to an intent, it could as well be other types of components.
Now I will jump into the example which you can download from here:


This example has 2 activities:
1. InvokingActivity
2. InvokedActivity
The InvokingActivity has a button "Invoke Next Activity" which when clicked explicitly calls the "InvokedActivity" class.
The relevant part of the code is here:

        Button invokingButton = (Button)findViewById(R.id.invokebutton);
        invokingButton.setOnClickListener(new OnClickListener() {
        

        
public void onClick(View v) {
        
Intent explicitIntent = new Intent(InvokingActivity.this,InvokedActivity.class);
         startActivity(explicitIntent);
        
}
        });

As explained in part 1 of the series, this is very much like an API call with compile time binding.
NOTE: The layout for InvokingActivity is defined in main.xml and for InvokedActivity in InvokedActivity.xml. The downloadable example can be opened in Eclipse Ganymede as an android project and can be executed.
In the next part of the series, we will see how to work with implicit intents which also needs us to understand intent-filters

60 comments:

  1. HI Sai Geetha,

    Doing Great Job...
    learning new things all the people to.
    sharing what we have learned do only some people like u......

    ReplyDelete
  2. Very glad to have found your blog! I am pretty new to any kind of programming, and I was wondering if you would have any tips on using Eclipse for android development. For example what packages work best. Thanks again my friend!

    ReplyDelete
  3. hello..
    do you know how to use alert dialog that when the user click ok button and then it will redirect the user to go another page?

    ReplyDelete
  4. I have a doubt not regarding android , but regarding java?
    wat is the purpose of using JavaVirtualMachine(JVM) ?
    how it serves the purpose of platform independency in java?
    how it differs from other platform dependent languages like c/c++?
    Can u give elaborate and simple explanation for this doubt?
    -thanks in advance

    ReplyDelete
    Replies
    1. Hi,
      Java is a platform independent language developed mainly for Web browser developemnt.
      JVM is an interpreter. Unlike C/C++ Java is platoform independent.
      Which means, It must generate a binary that is understood by all the platforms. But, it is not possible. Here JVM comes into play. JVM, comes with Java run time environment, interprets the Bytecode developed while compiling Java Source Code.

      Hence, If you have any Java Byte code, it runs on all the platofrms that have JVM unlike C/C++ where a .exe generated on Windows platform cannot run on Linux platform.
      I guess you understood it..

      Delete
    2. That's why JNI library is there to convert native code. Learn about JNI, you will understand better, how to use native code in java.

      Delete
  5. hi sai,
    another doubt in corejava?
    wat is the purpose of using hashtable?
    why should vector() has its initial capacity set as 10?
    can u give me solution for these doubts?

    --thanks in advance

    ReplyDelete
  6. Hai Sai Geetha,

    Hey i'm amazed by looking this blog,you are sharing worth one to all of us, thanks a lot.
    And one request i'm in need of some more code on services,please will u provide.?

    ReplyDelete
  7. Hi Sai,

    It is really a great work and the way in which u r sharing the knowledge is stupendous.Please can you help me out from ApplicationA how to call an activity which resides in ApplicatioB
    using explicit intents.
    I tried harde but I was not able to do so,as I am very new to android and mobile apps as well.

    Regards,
    Sridhar

    ReplyDelete
  8. Hi Sai,

    It is really a great work and the way in which u r sharing the knowledge is stupendous.Please can you help me out from ApplicationA how to call an activity which resides in ApplicatioB
    using explicit intents.
    I tried harde but I was not able to do so,as I am very new to android and mobile apps as well.

    Regards,
    Sridhar

    ReplyDelete
  9. Hi Sai Geetha,
    Thanks for your valuable information on android. I have one doubt below i am posting my question, if possible can you give me the solution, you can mail the solution to "bsabareesh@gmail.com".

    My activity have two radio button in the middle of the screen, on the top of the two radio buttons, i need to scroll the different advertisements continuously from the right of the screen to the left. In what way i have to do, I kept the radio buttons, scrolling advertisements is left. Please help me to achieve this activity.

    Thanks in advance.

    ReplyDelete
  10. Thank you so much! I'd been trying to figure out how to do this for a while.

    ReplyDelete
  11. Hi Geetha, you are doing Very Great Job, AM suman Narayana Working for LG on Messaging domain, I would like to give you one Input we can extend this blog to the domain specific, from messaging domain I can contribute, and also we can explore much on framework level, please kindly reply your interest to suman.rohith@gmail.com

    ReplyDelete
  12. Hi ,
    Am new to this Android SDK platform,so could you people help me out to solve my issue.
    so lets discuss brief about my issue, am developing small application in which am using sppiner to list all country states and zip codes so my question is when i select one country state in a list it should automatically populate and display its corresponding zip code.

    Awaiting for response

    Thanks in advance,
    Madhu

    ReplyDelete
  13. Hi Geetha,

    I have some queries regarding android SDK.
    here are my problem statememts,

    1.How to place border around some fields in UI.
    2.How to call another activity from current activity e.g. making a phone call from current activity.
    3.How to use Pagination.

    and its very usefull if you provide any mail id so that i can mail you my queries directly becz i need to solve ASAP and till have lot many questions to get it solved

    thnaks in advance,
    Madhu

    ReplyDelete
  14. Hi Sridhar,

    You can communicate between two applications through intents only of the called application declares in its manifest file that it can handle a call to a specific intent. Most often, this is done through implicit intents. You can however call it explicitly too. But the pre-requisite for that is called application should declare its intent or ability to respond to a call in its manifest file.

    ReplyDelete
  15. Noble job!! Is it possible for u to mail the sample code as ppl cant open filesharinf sites in most of the workplaces :(

    ankur296@gmail.com

    ReplyDelete
  16. hi ,

    on downloading sample codes, it leads to a mirror site. can you create another blog/page only for sample code which can be linked to this tutorial page. Because in workplace, we can't refer any mirror site for reference.

    ReplyDelete
  17. Hi Sai,

    I building an application which step by step working is given below

    1.My Activity is start in which I create a server UDP Socket Which wait fot data from client side.

    2. Then i press to Home Button click browser Icon and start You Tube Video.

    3. My Background Activity finds data send by client and generate a dialog window Activity with "yes" and "No" Button

    4. After clicking on any Button the dialog window is disappear

    I have done the all above task.But my problem is

    1. when Dialog window appear the You Tube Video is Stop and never resume even after the Dialog window Activity and UDP Server Activity is pause.

    2. Can I start my first Activity(UDP SERVER SOCKET) as a service?

    ReplyDelete
  18. Hello, I am familiar with other languages but new to Java. I don't understand what invoked the InvokingActivity at the start of the run.

    Thanx

    ReplyDelete
  19. Hi this is sathish, i am very new to android development, I read your blog and examples.I appreciated it. I need some help.I have same scenario like below for a media player application, can you please refer this link,
    http://efreedom.com/Question/1-3556196/Android-Can-Send-Activity-Background-Call


    Can you give a solution ,

    thanks in advance
    sathish.avunoori@gmail.com

    ReplyDelete
  20. Hi Sai,

    Could you pls suggest a method to store items in a list permanently using shared preferences and Map?

    Thanks in advance,
    Anju
    m_anju@rocketmail.com

    ReplyDelete
  21. Thank you for your effort! Your explanations are a very helpful starting point if one doesn't know a thing about androiding yet and aspires to get a basic understanding.

    ReplyDelete
  22. Chandu..

    Hi Sai,
    How to get geopoint of my location,pls help me regards.

    ReplyDelete
  23. Hi Sai Madam


    Am fersher,jst now i got job in UK based company as a tester now am in Bluetooth and Wifi domain.

    I was started writing Android application,this blog helpd me to learn lot of things on android.

    Thank you vry much ,hopn U will solve my doubts on application .

    ReplyDelete
  24. Hi Sailatha,
    superb tutorials easy to understand.
    thanks for a lot

    ReplyDelete
  25. Hello Madam

    I am Sai.I have a small query here,I recently started android programming and I am finding it very interesting.I have decided to create an application on my own which is called ElectricityBilling Application.

    I created 3 activities...
    1.ElecBillActivity(Screenshot: http://tinyurl.com/3mhw3h4 )
    2.AddBillActivity(Screenshot: http://tinyurl.com/3scl7xr )
    3.ResultActivity(Screenshot: http://tinyurl.com/3hrglex )

    As you can see in the above screenshots...I successfully enterd into the 2nd activity by using the intents..but as soon as I click the Submit button in the 2nd activity,I am getting an exception.I tried many ways,but i am unable to understand the problem.I am also providing the link for my code (http://www.4shared.com/file/w9sPrKc8/ElectricityBilling.html)

    I am really interested to complete this as soon as possible,I request some very much appreciated assistence from you!

    Thanks!

    ReplyDelete
  26. Hi..
    Thanks for helping us..Really ROX.bukmarkd. :)

    ReplyDelete
  27. Hi,
    Thanks for this good android tutorial.
    Extreme Java

    ReplyDelete
  28. Nice blog. I will keep visiting this blog very often.
    Thanks , for much information,Keep sharing such a wonderful information..!

    ReplyDelete
  29. Hello and thank you for this superb blog, this awesome tutorial! I am very fortunate to have found it.

    ReplyDelete
  30. HI,
    Sai Geetha
    Myself Praveen. This is superb tutorial for beginners.. If u give some more examples of different programs it will be helpful.

    ReplyDelete
  31. This is a request for help.

    I am just starting to develop apps for the Android platform and I am struggling with a major hurdle at this time. For my current app, I need to have a video in it. My app contains strings and still images. Now, after the text and images, I want to have a video (e.g.,one of my videos in YOUTUBE) that will play when the running app gets past this chunk of text and images.
    How can this task be accomplished successfully?
    I emphasize "successfully" because I tried everything I could find via Google but nothing works so far.

    Please reply with step-by-step instructions, if possible.

    Thank you.

    ReplyDelete
  32. hi i am naresh.i am working as a android developer in small organisation.i am fresh Btech graduate.wili i get better oppertunities as a android developer after getting experience.will i get a job in MNC's.

    ReplyDelete
  33. Hi, I am Tarun , from Bangladesh. I am working as a junior android developer a firm. I attached your given code, but code showing error in my pc.

    ReplyDelete
  34. Hai sai how to use intent for multiple activity?can u explain?

    ReplyDelete
  35. This is one of the useful post.Your blog is presenting very good and new Information.Your blog is presenting variety and good Information.I like this post.Good.Android app developers

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

    ReplyDelete
  37. Thank you very much for this great tutorial

    ReplyDelete
  38. hi sai..
    thanks for ur information...

    ReplyDelete
  39. Hi Sai,

    Really very good article, I am new to android, according to you how do you see job chances in android here in india.

    ReplyDelete
  40. plagiarism? http://alotaboutandroid.blogspot.com/2012/03/android-tutorial-for-beginners-part-3.html

    ReplyDelete
  41. Yes,

    Thanks for bringing this to my notice. It looks like the alotaboutandroid is copying my posts exactly and putting it into his blog. A shame indeed.

    When we want to share our knowledge freely, people want to misuse it!!

    ReplyDelete
  42. Hi Geetha, you are doing Very Great Job, Thanks , for much information,Keep sharing such a wonderful information..!

    ReplyDelete
  43. Unfortunately, they are not the only ones:

    e.g. http://androidmaterial.blogspot.com/2011/07/explicit-intent-for-android.html

    And much more:
    http://copyscape.com/?q=http%3A%2F%2Fsaigeethamn.blogspot.com%2F2009%2F08%2Fandroid-developer-tutorial-for.html

    You should email them warning for infringing your copyrights. However, possibly you should put a copyright first :-) It is not so hard in fact, you can just put a link to Creative Commons or so (allowing to copy whatever they want, but giving you the credit for your original creation), and it would be clear they are doing something they shouldn't.

    My 2 cents.

    ReplyDelete
  44. Hello madam this is chandra sekhar.
    can you please help me by providing the example of intents without entering the details dont allowing it togo to next activity.
    Please help me madam

    ReplyDelete
  45. This is very helpful! Thank you very much for sharing your knowledge.

    ReplyDelete
  46. Hi Geeta, Your tutorials appear to be very helpful but I tried running them with Android 4.0. I am new to Android development and just learning. I took the Implicit Intent and rewrote it instead of directly running your tutorial to get hands on and I think I have everything pulled from your source but when I start my android in debug mode, I do not get the button or anything like that. I get an android screen which does not show any buttons. What could I be doing wrong.

    Thanks
    I have very careful pulled all your code together and it all compiles.

    Thanks

    Dhiren

    ReplyDelete
  47. hi sai
    this is Navan...my problem is when i am ready to execute the program always it displays error as R.layout.next is not resloved......plz send me the answer i am new to the android

    ReplyDelete
  48. How can mobile app developers help your business? There are 'n' of Android development company are there in that Rize is a most rated company.

    ReplyDelete
  49. hi Sai
    this is manasa...pls tell me in how many types to create tha database in android..everytime am using db.exex.SQL()..and in ur blog u just give syntaxes only..why should u go for the programs....

    ReplyDelete
  50. Hi Sai,
    All the very best wishes ,I will love to read an article on "RIL".
    Can u post it on our blog .

    Thanks &Regards
    Nihar

    ReplyDelete
  51. hi

    U are doing very good job.

    ReplyDelete
  52. hi,

    could you please list the same examples for MAC OS X also ?

    ReplyDelete
  53. Sai,

    your post are very organized way and easy understandable. Doing a good job.

    Thanks a lot for your time and sharing. Keep posting ...

    ReplyDelete
  54. For the beginners this is really nice post.because this provides basic concept of android development.both the part are good for viewers.

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

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

    ReplyDelete
  57. hai madam this vinoth kumar(Moorthy student) from chennai what is strict intent

    ReplyDelete