Monday, November 11, 2013

Intent


Overview –
Intent is an abstract description of an operation to be performed. It can be used with startActivity to launch an Activity, broadcastIntent to send it to any interested BroadcastReceiver components to communicate with a background Service.
For example:- an Activity can send an Intents to the Android system which starts another Activity.
Implicit intents are often used to send message from one activity to in-built android activity. Implicit Intents have not specified a component; instead, They specify the action which should be performed and optionally an URI which should be used for this action.  Here, we do not declare the target component and hence is typically used for activating components of other applications seamlessly.
Simple Program (Tutorial) :-
    Create a new Android application "Implicit Intent" with package name “com.intent.implicit” & a Activity called "ImplicitActivity.java".
     Write following code in  "main.xml" file in the "res/layout" folder. Change the   layout file "main.xml" to the following.

     Write following  java code in “ImplicitActivity.java” file in src/com.intent.implicit” .




    Add following permission in “AndroidManifest.xml” file in “res” folder.

   Explicit intent to an instance of the designated target class Explicit Intents explicitly names the component which should be called by the Android system, by using the Java class as identifier. 

   Simple Program (Tutorial):-
      Create a new Android application “Explicit Intent" with package name “com.intent.explicit” & two activities called "ExplicitActivity.java"  & “Second.java”.
      Write following code in  "main.xml" & “second.xml” file in the "res/layout" folder.
    “main.xml”

“second.xml”
      Write following java code in “ExplicitActivity.java” & “Second.java” files in src/com.intent.explicit” .
I      
“ExplicitActivity.java”
   
Second.java”
Add/write following code in “AndroidManifest.xml” file in “res” folder. 

4 comments:

  1. Hello Sir

    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
  2. Hello Ankit

    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,
    Sanjana

    ReplyDelete
  3. Hi Sanjana,

    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
  4. Hello Ankit
    Thanks for helping me ..Really Its very usefull and helping information
    you rock yaar..

    Regards,
    Sanjana

    ReplyDelete

Mastering Jetpack Compose: Key Methods for Efficient Android UI Development

Jetpack Compose is a modern toolkit for building native Android UI. It simplifies UI development by providing a declarative approach, making...