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
8
votes
9 answers

How to display 2 textviews in the same line in Android

I have my layout xml file:
String
  • 3,660
  • 10
  • 43
  • 66
8
votes
1 answer

Android Add Event to Calendar using Intent, get EventID

I'm trying to add event through an calendar intent. However, I can't figure out how to get the event ID of the event just added. Intent intent = new Intent(Intent.ACTION_EDIT); intent.setType("vnd.android.cursor.item/event"); …
Mike
  • 826
  • 11
  • 31
8
votes
2 answers

What Does Intent.putExtra will do

I am new to android and I use intents to transfer data from one Activity to another. I just wanted to know whether the object reference or object copy is sending to the second Activity.
Software Sainath
  • 1,040
  • 2
  • 14
  • 39
8
votes
1 answer

Intent.ACTION_VIEW - Multiple files

I have a requirement to show multiple files (2 or more each of images, music or video, but only one type). Given a series of thumbnails or filenames, the user should be able to select a chekbox and preview the selection. IF the user selects…
Martin
  • 4,711
  • 4
  • 29
  • 37
8
votes
4 answers

How to send data through intent in android without opening another activity?

here is my code for sending data by intent but i don't want open another activity i just want to send the data without opening it.. Bundle contain = new Bundle(); contain.putString("key4", item); contain.putString("price",…
scripter
  • 1,416
  • 4
  • 19
  • 35
8
votes
2 answers

Android: PendingIntent from Notification doesn't trigger the onCreate() if bringing Activity back on Screen

guess I'm having some misunderstandigs with the Intent Flags.. What I'm trying to do is, I'm having a radio streaming applications, which has two Activities (PlayerApplication and SettingsScreen). I have a Service.class for Streaming which runs in…
longi
  • 11,104
  • 10
  • 55
  • 89
8
votes
3 answers

How can I find out which intent a service (not in my app) is started by?

I want to find out how Google Maps service is automatically started. When I dump logcat of main buffer or events buffer, I can only find out which component of Google Maps is started, but no clues about "Who" (package) started it, and "How"…
Oasis Feng
  • 7,490
  • 3
  • 31
  • 44
8
votes
3 answers

share intent via facebook for android jelly bean

I want to share some image and text via Facebook from android jelly bean. it work's in all devices except android jelly bean. Anybody please help me how to resolve this issue. my code Intent shareIntent = new…
8
votes
1 answer

BadParcelableException - BroadcastReceiver intent crash

This error seems to happen sporadically, which is odd. It usually works fine, but occasionally it creeps up. Here is my code, which is in a BroadcastReceiver: public void onReceive(Context context, Intent intent) { MyCustomResponseMsg message…
8
votes
3 answers

How to send data from one application to other application in android?

I need to send some string data from my one application activity to my other application activity in android and not between the activities within the same application. How to do that? What intent filters my other application need to declare? Please…
SACHIN DHIVARE
  • 115
  • 1
  • 1
  • 7
8
votes
1 answer

Android: BroadcastReceiver on application install / uninstall

I want to install an apk file and set a broadcast-receiver in order to catch information concerning install status. I have prepared a BroadcastReceiver class : public class newPackageReceiver extends BroadcastReceiver { @Override public…
johann
  • 1,115
  • 8
  • 34
  • 60
8
votes
3 answers

How to get Category of application using package name

I am having two or more application having my specified category like and I am able to get all packages having this category by : final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null); …
8
votes
3 answers

Obtaining usb cable plugged IN/OUT event using EXTRA_PLUGGED does not work

My intention is to have saved in Preferences current status of Android device usb/power cable: connected/disconnected. From Developer site I see that there are two Intent for obtaining that status: ACTION_POWER_CONNECTED / DISCONNECTED. So I used…
user1128166
  • 131
  • 1
  • 2
  • 4
8
votes
4 answers

java.lang.OutOfMemoryError in android while getting image from gallery in android

I am picking a picture from gallery using code public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.gallery); Intent i = new Intent(Intent.ACTION_PICK,…
Shirish Herwade
  • 11,461
  • 20
  • 72
  • 111
8
votes
1 answer

Passing values in Pending Intents Android

Can we pass the arguments in a pending intent for the Background Process.. Intent ij = new Intent(context,DemoActivity.class); PendingIntent operation = PendingIntent.getActivity(getBaseContext(),0,ij,Intent.FLAG_ACTIVITY_NEW_TASK); …