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
1600
votes
43 answers

How can I open a URL in Android's web browser from my application?

How to open an URL from code in the built-in web browser rather than within my application? I tried this: try { Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(download_link)); startActivity(myIntent); } catch…
Arutha
  • 26,088
  • 26
  • 67
  • 80
1527
votes
53 answers

How do I pass data between Activities in Android application?

I have a scenario where, after logging in through a login page, there will be a sign-out button on each activity. On clicking sign-out, I will be passing the session id of the signed in user to sign-out. Can anyone guide me on how to keep session id…
UMAR-MOBITSOLUTIONS
  • 77,236
  • 95
  • 209
  • 278
1100
votes
14 answers

How to manage startActivityForResult on Android

In my activity, I'm calling a second activity from the main activity by startActivityForResult. In my second activity, there are some methods that finish this activity (maybe without a result), however, just one of them returns a result. For…
Hesam
  • 52,260
  • 74
  • 224
  • 365
928
votes
35 answers

How to send an object from one Android Activity to another using Intents?

How can I pass an object of a custom type from one Activity to another using the putExtra() method of the class Intent?
UMAR-MOBITSOLUTIONS
  • 77,236
  • 95
  • 209
  • 278
889
votes
35 answers

How to pass an object from one activity to another on Android

I am trying to work on sending an object of my customer class from one Activity and displaying it in another Activity. The code for the customer class: public class Customer { private String firstName, lastName, address; int age; …
Adil Bhatty
  • 17,190
  • 34
  • 81
  • 118
857
votes
18 answers

How do I get extra data from intent on Android?

How can I send data from one activity (intent) to another? I use this code to send data: Intent i=new Intent(context,SendMessage.class); i.putExtra("id", user.getUserAccountId()+""); i.putExtra("name",…
Adham
  • 63,550
  • 98
  • 229
  • 344
848
votes
10 answers

Sending an Intent to browser to open specific URL

I'm just wondering how to fire up an Intent to the phone's browser to open an specific URL and display it. Can someone please give me a hint?
poeschlorn
  • 12,230
  • 17
  • 54
  • 65
717
votes
28 answers

How to start new activity on button click

In an Android application, how do you start a new activity (GUI) when a button in another activity is clicked, and how do you pass data between these two activities?
Adham
  • 63,550
  • 98
  • 229
  • 344
699
votes
25 answers

Sending Email in Android using JavaMail API without using the default/built-in app

I am trying to create a mail sending application in Android. If I use: Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); This will launch the built-in Android application; I'm trying to send the mail on button click directly…
Vinayak Bevinakatti
  • 40,205
  • 25
  • 108
  • 139
683
votes
27 answers

How to open the Google Play Store directly from my Android application?

I have open the Google Play store using the following code Intent i = new Intent(android.content.Intent.ACTION_VIEW); i.setData(Uri.parse("https://play.google.com/store/apps/details?id=my packagename ")); startActivity(i);. But it shows me a…
Rajesh Kumar
  • 6,868
  • 3
  • 15
  • 15
678
votes
40 answers

Send Email Intent

Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/html"); intent.putExtra(Intent.EXTRA_EMAIL, "emailaddress@emailaddress.com"); intent.putExtra(Intent.EXTRA_SUBJECT, "Subject"); intent.putExtra(Intent.EXTRA_TEXT, "I'm email…
dira
  • 30,304
  • 14
  • 54
  • 69
622
votes
18 answers

What is an Android PendingIntent?

I read the Android Documentation but I still need some more clarification. What exactly is a PendingIntent?
Rakesh
  • 14,997
  • 13
  • 42
  • 62
602
votes
23 answers

Android: Go back to previous activity

I want to do something simple on android app. How is it possible to go back to a previous activity. What code do I need to go back to previous activity
Troj
  • 11,781
  • 12
  • 40
  • 49
557
votes
18 answers

How to launch an Activity from another Application in Android

I want to launch an installed package from my Android application. I assume that it is possible using intents, but I didn't find a way of doing it. Is there a link, where to find the information?
Bastian
  • 9,505
  • 6
  • 19
  • 8
536
votes
58 answers

How do I get the currently displayed fragment?

I am playing with fragments in Android. I know I can change a fragment by using the following code: FragmentManager fragMgr = getSupportFragmentManager(); FragmentTransaction fragTrans = fragMgr.beginTransaction(); MyFragment myFragment = new…
Leem.fin
  • 40,781
  • 83
  • 202
  • 354
1
2 3
99 100