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
121
votes
11 answers

intent.resolveActivity returns null in API 30

Looking at intent.resolveActivity != null but launching the intent throws an ActivityNotFound exception I wrote opening a browser or an application with Deep linking: private fun openUrl(url: String) { val intent = Intent().apply { …
120
votes
8 answers

How to pass a URI to an intent?

I'm trying to pass a URI-Object to my Intent in order to use that URI in another activity. How do I pass a URI? private Uri imageUri; .... Intent intent = new Intent(this, GoogleActivity.class); intent.putExtra("imageUri",…
Robert El
  • 1,247
  • 2
  • 10
  • 10
117
votes
3 answers

Can I click a button programmatically for a predefined intent?

I need the button click of the intent ACTION_SEND. Here there is no need of displaying UI. Can I get the "Send" button click from the MMS-SMSProvider in Android?
info
  • 2,152
  • 5
  • 22
  • 38
114
votes
3 answers

How to start an Intent by passing some parameters to it?

I would like to pass some variables in the constructor of my ListActivity I start activity via this code: startActivity(new Intent (this, viewContacts.class)); I would like to use similar code, but to pass two strings to the constructor. How is…
Pentium10
  • 204,586
  • 122
  • 423
  • 502
113
votes
13 answers

Android - java.lang.SecurityException: Permission Denial: starting Intent

I have a library (jar) on build path of my project. The project accesses the MainActivity in the jar, using the following intent: final Intent it = new Intent(); it.setClassName("com.example.lib",…
Ramanathan
  • 1,663
  • 4
  • 17
  • 24
113
votes
10 answers

Finish an activity from another activity

I want to finish one activity from another activity, like: In Activity [A], on button click, I am calling Activity [B] without finishing Activity [A]. Now in Activity [B], there are two buttons, New and Modify. When the user clicks on modify then…
Kanika
  • 10,648
  • 18
  • 61
  • 81
112
votes
8 answers

Pick any kind of file via an Intent in Android

I would like to start an intentchooser for apps which can return any kind of file Currently I use (which I copied from the Android email source code for file attachment) Intent intent = new…
ErGo_404
  • 1,801
  • 4
  • 18
  • 22
112
votes
7 answers

How do I show a marker in Maps launched by geo URI Intent?

I have a application where I want to show different locations (one at the time, picked by user input) by launching Google Maps with their specific geo coordinates. I'm currently using this (with real lat. and long. values of course): Intent intent =…
Specur
  • 3,240
  • 4
  • 23
  • 25
110
votes
10 answers
110
votes
3 answers

Intercepting links from the browser to open my Android app

I'd like to be able to prompt my app to open a link when user clicks on an URL of a given pattern instead of allowing the browser to open it. This could be when the user is on a web page in the browser or in an email client or within a WebView in a…
jamesh
  • 19,863
  • 14
  • 56
  • 96
108
votes
4 answers

What is the meaning of android.intent.action.MAIN?

I have seen so many different confusing explenations.. What is the meaning of
Gero
  • 12,993
  • 25
  • 65
  • 106
108
votes
2 answers

Where/How to getIntent().getExtras() in an Android Fragment?

With Activities, I used to do this: In Activity 1: Intent i = new Intent(getApplicationContext(), MyFragmentActivity.class); i.putExtra("name", items.get(arg2)); i.putExtra("category", Category); …
TheLettuceMaster
  • 15,594
  • 48
  • 153
  • 259
107
votes
9 answers

How to pass a parcelable object that contains a list of objects?

I have created a Parcelable object below, my object contains a List of Products. In my constructor how do I handle re-creating my Parcelable for the List? I have checked all of the methods available from the parcel and all that is available is…
Byron
  • 3,833
  • 9
  • 34
  • 39
107
votes
3 answers

what is the difference between sendStickyBroadcast and sendBroadcast in Android

What is the difference between sendStickyBroadcast and sendBroadcast in Android?
cobject
  • 1,071
  • 2
  • 8
  • 3
106
votes
2 answers

Reasons that the passed Intent would be NULL in onStartCommand

Is there any other reason that the Intent that is passed to onStartCommand(Intent, int, int) would be NULL besides the system restarting the service via a flag such as START_STICKY? Also, when the service is restarted by the system the…
rf43
  • 4,385
  • 3
  • 23
  • 28