Questions tagged [android-intent]

Questions regarding practical and advanced use of Intents, Intent Extras and Pending Intents to start an Activity, Service or to respond to a system or application event/notification via a BroadcastReceiver. (refer to info for basic familiarity)

From the Android Developers reference site:

An Intent facilitates performing late runtime binding between the code in different applications. Its most important use is in the launching of activities, where it can be thought of as the glue between activities. It is basically a passive data structure holding an abstract description of an action to be performed.

The Basics

Intents are used extensively within the Android Platform for telling the operating system that a certain action needs to be performed. At first glance, the apparent use of Intents is to start Activities (components that have a user interface). Upon gaining even a limited experience with Android development, it becomes clear that it is used for nearly every component within the Android platform.

Services are bound or started by Activities. BroadcastReceivers listen for Intents that are sent either by the operating system or other applications. Even Widgets cannot be placed onto the Home Screen without an Intent.

Intent Actions

The Action is the core of the Intent. It is simply a string that is passed to the operating system to indicate a given action. Some are general and provided directly by the platform. Others are specific to packages and unique tasks. This allows for any developer to create their own Intents with very little effort for either public or private use.

A Custom Intent Action follows the form "top.company.package.DO_SOMETHING", where: top is the top-level domain following usage conventions (com for commercial, org for non-commercial organization, edu for educational organization, etc); company is the company name of the developer; package is the name of the package; and DO_SOMETHING is a meaningful name describing the action. Android-provided Intents can be found at: Intent Filters

Example: com.softwareheroes.coolui.SHOW_LOG might show the log file for the Cool UI application made by the fictional commercial enterprise Software Heroes.

Intent Extras

Many times when starting another application component, developers will need to transmit information. The threading model can sometimes make this difficult, especially when communicating with different types of components. Intent Extras allow you to transmit a wide variety of data without having to resort to complex threading or security access levels. A full list of data types that can be transmitted and received is located here.

Pending Intents

Pending Intents are Intents that are created early to be fired later on behalf on the application that created it. Using this mechanism, an application may create an Intent to respond to a possible future event and even give that Intent to an external application. The most popularized use of these is in notifications, which require that when clicked on they perform some action.

When to Use This Tag

Since Intents are so widely used, it is hard to gauge when it might be appropriate to use this tag. In general, if you simply want to know which Intent starts which application or what the Intent is when a common system event occurs, one should refer to the reference or guide. These also link to several tutorials. If these resources do not address the specific need or query, then simply try and verify that the issue is really a lack of understanding with regard to Intents or the specific Intent.

Poor Example: How do I respond to an SMS message?

This is common knowledge and provided in the explanation of Intents on the Android Developer site.

Good Example: Can I pass the extras from Intent to another safely?

30913 questions
440
votes
18 answers

Launching Google Maps Directions via an intent on Android

My app needs to show Google Maps directions from A to B, but I don't want to put the Google Maps into my application - instead, I want to launch it using an Intent. Is this possible? If yes, how?
Lars D
  • 8,483
  • 7
  • 34
  • 37
435
votes
16 answers

Launch custom android application from android browser

Can anybody please guide me regarding how to launch my android application from the android browser?
Parimal Modi
  • 4,359
  • 3
  • 16
  • 3
384
votes
21 answers

How to make a phone call using intent in Android?

I'm using the following code to make a call in Android but it is giving me security exception please help. posted_by = "111-333-222-4"; String uri = "tel:" + posted_by.trim() ; Intent intent = new Intent(Intent.ACTION_CALL); …
367
votes
18 answers

How to use putExtra() and getExtra() for string data

Can someone please tell me how exactly to use getExtra() and putExtra() for intents? Actually I have a string variable, say str, which stores some string data. Now, I want to send this data from one activity to another activity. Intent i = new…
Shaista Naaz
  • 8,281
  • 9
  • 37
  • 50
363
votes
14 answers

What is an Intent in Android?

What is an Intent in Android? Can someone elaborate with an example? What are the types of Intents, and why we are using them? Why are Intents so important in Android?
Nikunj Patel
  • 21,853
  • 23
  • 89
  • 133
362
votes
22 answers

How to get a list of installed android applications and pick one to run

I asked a similar question to this earlier this week but I'm still not understanding how to get a list of all installed applications and then pick one to run. I've tried: Intent intent = new…
2Real
  • 4,321
  • 4
  • 23
  • 27
360
votes
39 answers

Android: Clear the back stack

In Android I have some activities, let's say A, B, C. In A, I use this code to open B: Intent intent = new Intent(this, B.class); startActivity(intent); In B, I use this code to open C: Intent intent = new Intent(this,…
Martin
  • 7,190
  • 9
  • 40
  • 48
332
votes
13 answers

Sending data back to the Main Activity in Android

I have two activities: main activity and child activity. When I press a button in the main activity, the child activity is launched. Now I want to send some data back to the main screen. I used the Bundle class, but it is not working. It throws…
Rajapandian
  • 7,059
  • 11
  • 37
  • 27
313
votes
5 answers

Android - Adding at least one Activity with an ACTION-VIEW intent-filter after Updating SDK version 23

I am getting the following tool tip in AndroidManifest.xml: App is not indexable by Google Search; consider adding at least one Activity with an ACTION-VIEW intent-filler. See issue explanation for more details. Adds deep links to get your app into…
Pratik Butani
  • 60,504
  • 58
  • 273
  • 437
306
votes
14 answers

Listing all extras of an Intent

For debugging reasons I want to list all extras (and their values) of an Intent. Now, getting the keys isn't a problem Set keys = intent.getExtras().keySet(); but getting the values of the keys is one for me, because some values are…
stefan.at.kotlin
  • 15,347
  • 38
  • 147
  • 270
296
votes
21 answers

"Rate This App"-link in Google Play store app on the phone

I'd like to put a "Rate This App"-link in an Android App to open up the app-listing in the user's Google Play store app on their phone. What code do I have to write to create the market:// or http://-link open in the Google Play store app on the…
Adreno
  • 3,263
  • 4
  • 15
  • 7
280
votes
20 answers

Get/pick an image from Android's built-in Gallery app programmatically

I am trying to open an image / picture in the Gallery built-in app from inside my application. I have a URI of the picture (the picture is located on the SD card). Do you have any suggestions?
Michael Kessler
  • 14,245
  • 13
  • 50
  • 64
237
votes
7 answers

How do I get the dialer to open with phone number displayed?

I don't need to call the phone number, I just need the dialer to open with the phone number already displayed. What Intent should I use to achieve this?
Nik
  • 7,114
  • 8
  • 51
  • 75
236
votes
12 answers

Parcelable encountered IOException writing serializable object getactivity()

so I am getting this in logcat: java.lang.RuntimeException: Parcelable encountered IOException writing serializable object (name = com.resources.student_list.Student) I know this means that my student class is not serializable, but it is, here is…
user2896762
  • 2,427
  • 3
  • 13
  • 12
221
votes
13 answers

How to send parameters from a notification-click to an activity?

I can find a way to send parameters to my activity from my notification. I have a service that creates a notification. When the user clicks on the notification I want to open my main activity with some special parameters. E.g an item id, so my…
Vidar Vestnes
  • 42,644
  • 28
  • 86
  • 100