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
217
votes
20 answers

Android Gallery on Android 4.4 (KitKat) returns different URI for Intent.ACTION_GET_CONTENT

Before KitKat (or before the new Gallery) the Intent.ACTION_GET_CONTENT returned a URI like this content://media/external/images/media/3951. Using the ContentResolver and querying for MediaStore.Images.Media.DATA returned the file URL. In KitKat…
198
votes
12 answers

How to filter specific apps for ACTION_SEND intent (and set a different text for each app)

How can you filter out specific apps when using the ACTION_SEND intent? This question has been asked in various ways, but I haven't been able to gather a solution based on the answers given. Hopefully someone can help. I would like to provide the…
Kyle Clegg
  • 38,547
  • 26
  • 130
  • 141
195
votes
11 answers

Using Intent in an Android application to show another activity

In my Android application, I have two activity classes. I have a button on the first one and I want to show the second when it is clicked, but I get an error. Here are the classes: public class FirstActivity extends Activity { @Override …
Tai Squared
  • 12,273
  • 24
  • 72
  • 82
189
votes
16 answers

How can I return to a parent activity correctly?

I have 2 activities (A and B) in my android application and I use an intent to get from activity A to activity B. The use of parent_activity is enabled:
ashiaka
  • 3,994
  • 8
  • 32
  • 45
186
votes
5 answers

How to implement my very own URI scheme on Android

Say I want to define that an URI such as: myapp://path/to/what/i/want?d=This%20is%20a%20test must be handled by my own application, or service. Notice that the scheme is "myapp" and not "http", or "ftp". That is precisely what I intend: to define…
punnie
  • 2,404
  • 4
  • 17
  • 32
185
votes
10 answers

Android: Share plain text using intent (to all messaging apps)

I'm trying to share some text using an intent: Intent i = new Intent(android.content.Intent.ACTION_SEND); i.setType("text/plain"); i.putExtra(android.content.Intent.EXTRA_TEXT, "TEXT"); and warping with…
skgskg
  • 1,873
  • 2
  • 12
  • 7
184
votes
9 answers

How to switch activity without animation in Android?

How can I use properly the Intent flag FLAG_ACTIVITY_NO_ANIMATION in AndroidManifest file? I supose my problem is trivial, but I can't find good example or solution to it.
woyaru
  • 5,544
  • 13
  • 54
  • 92
173
votes
11 answers

Start Activity from Service in Android

Android: public class LocationService extends Service { @Override public void onStart(Intent intent, int startId) { super.onStart(intent, startId); startActivity(new Intent(this, activity.class)); } } I launched this…
d-man
  • 57,473
  • 85
  • 212
  • 296
172
votes
14 answers

Android ACTION_IMAGE_CAPTURE Intent

We are trying to use the native camera app to let the user take a new picture. It works just fine if we leave out the EXTRA_OUTPUT extra and returns the small Bitmap image. However, if we putExtra(EXTRA_OUTPUT,...) on the intent before starting it,…
Drew
  • 1,769
  • 4
  • 12
  • 5
163
votes
2 answers

onNewIntent() lifecycle and registered listeners

I'm using a singleTop Activity to receive intents from a search-dialog via onNewIntent(). What I noticed is that onPause() is called before onNewIntent(), and then afterwards it calls onResume(). Visually: search dialog initiated search intent…
DJayC
  • 1,765
  • 3
  • 12
  • 10
160
votes
13 answers

How to detect incoming calls, in an Android device?

I'm trying to make an app like, when a call comes to the phone I want to detect the number. Below is what I tried, but it's not detecting incoming calls. I want to run my MainActivity in background, how can I do that? I had given the permission in…
Jesbin MJ
  • 3,219
  • 7
  • 23
  • 28
156
votes
2 answers

Android Respond To URL in Intent

I want my intent to be launched when the user goes to a certain url: for example, the android market does this with http://market.android.com/ urls. so does youtube. I want mine to do that too.
Isaac Waller
  • 32,709
  • 29
  • 96
  • 107
156
votes
16 answers

Allow user to select camera or gallery for image

What I'm trying to do seems very simple, but after a few days of searching I can't quite figure it out. I have an application that allows the user to select multiple(up to 5) images. I'm using an ImageView. When the user clicks on the ImageView,…
156
votes
22 answers

launch sms application with an intent

I have a question about an intent... I try to launch the sms app... Intent intent = new Intent(Intent.ACTION_MAIN); intent.setType("vnd.android-dir/mms-sms"); int flags = Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP | …
Olivier69
  • 1,561
  • 2
  • 10
  • 4
155
votes
10 answers

install / uninstall APKs programmatically (PackageManager vs Intents)

My application installs other applications, and it needs to keep track of what applications it has installed. Of course, this could be achieved by simply keeping a list of installed applications. But this should not be necessary! It should be the…
Håvard Geithus
  • 5,544
  • 7
  • 36
  • 51