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
155
votes
19 answers

Android YouTube app Play Video Intent

I have created a app where you can download YouTube videos for android. Now, I want it so that if you play a video in the YouTube native app you can download it too. To do this, I need to know the Intent that the YouTube native app puts out in order…
Isaac Waller
  • 32,709
  • 29
  • 96
  • 107
147
votes
13 answers

Check if application is installed - Android

I'm trying to install apps from Google Play. I can understand that on opening the Google Play store URL, it opens the Google Play and when I press the back button, the activity resumes. Intent marketIntent = new Intent(Intent.ACTION_VIEW,…
Siddharthan Asokan
  • 4,321
  • 11
  • 44
  • 80
146
votes
4 answers

PendingIntent does not send Intent extras

My MainActicity starts RefreshService with a Intent which has a boolean extra called isNextWeek. My RefreshService makes a Notification which starts my MainActivity when the user clicks on it. this looks like this: Log.d("Refresh",…
maysi
  • 5,457
  • 12
  • 34
  • 62
144
votes
8 answers

Intent - if activity is running, bring it to front, else start a new one (from notification)

My app has notifications, which - obviously - without any flags, start a new activity every time so I get multiple same activities running on top of each other, which is just wrong. What I want it to do is to bring the activity specified in the…
urSus
  • 12,492
  • 12
  • 69
  • 89
141
votes
21 answers

Clearing intent

My Android app is getting called by an intent that is passing information (pendingintent in statusbar). When I hit the home button and reopen my app by holding the home button it calls the intent again and the same extras are still there. …
Mars
  • 4,197
  • 11
  • 39
  • 63
141
votes
20 answers

Open another application from your own (intent)

I know how to update my own programs, and I know how to open programs using the a predefined Uri (for sms or email for example) I need to know how I can create an Intent to open MyTracks or any other application that I don't know what intents they…
AndersWid
  • 1,413
  • 2
  • 10
  • 4
140
votes
19 answers

Kotlin Android start new Activity

I want to start another activity on Android but I get this error: Please specify constructor invocation; classifier 'Page2' does not have a companion object after instantiating the Intent class. What should I do to correct the error? My…
J Adonai Dagdag
  • 1,835
  • 2
  • 10
  • 22
140
votes
5 answers

What's "requestCode" used for on PendingIntent?

Background: I'm using PendingIntent for alarms via AlarmManager. The problem: At first I thought that in order to cancel previous ones, I must provide the exact requestCode that I've used before to start the alarm. But then I've found out I was…
android developer
  • 114,585
  • 152
  • 739
  • 1,270
139
votes
26 answers

Sending message through WhatsApp

Since I found some older posts, that tell that whatsapp doesn't support this, I was wondering if something had changed and if there is a way to open a whatsapp 'chat' with a number that I'm sending through an intent?
Diego
  • 4,011
  • 10
  • 50
  • 76
137
votes
3 answers

BroadcastReceiver with multiple filters or multiple BroadcastReceivers?

I have an Android Activity that needs to catch two different broadcasts. My current approach is to have a single BroadcastReceiver within the Activity and catch both the broadcasts with it: public class MyActivity extends Activity { private…
Lorenzo Polidori
  • 10,332
  • 10
  • 51
  • 60
135
votes
4 answers

difference and when to use getApplication(), getApplicationContext(), getBaseContext() and someClass.this

I'm new to android and I'm trying to understand the difference between getApplication(), getApplicationContext(), getBaseContext(), getContext() and someClass.this and especially when to use the these methods in the following code lines: When I…
Pheonix7
  • 2,131
  • 5
  • 21
  • 38
134
votes
18 answers

Changing position of the Dialog on screen android

I made a simple AlertDialog in my Activity: View view = layoutInflater.inflate(R.layout.my_dialog, null); AlertDialog infoDialog = new AlertDialog.Builder(MyActivity.this) .setView(view) …
Leem.fin
  • 40,781
  • 83
  • 202
  • 354
129
votes
9 answers

How to check if an intent can be handled from some activity?

I have this method so far , but it came up like something is missing for example I have a file /sdcard/sound.3ga that returns false ( like there is no activity that can handle this type of file ) , But when I open it from the file manager it opens…
Lukap
  • 31,523
  • 64
  • 157
  • 244
125
votes
18 answers

Android draw a Horizontal line between views

I have My Layout like below:
String
  • 3,660
  • 10
  • 43
  • 66
122
votes
8 answers

What is the purpose of "android.intent.category.DEFAULT"?

What is the purpose of using android.intent.category.DEFAULT in the Category field of Intent Filters?
Pravy
  • 2,165
  • 5
  • 22
  • 28