Tutorial by Examples

This example will start DestinationActivity from OriginActivity. Here, the Intent constructor takes two parameters: A Context as its first parameter (this is used because the Activity class is a subclass of Context) The Class of the app component to which the system should deliver the Intent (i...
This example illustrates sending a String with value as "Some data!" from OriginActivity to DestinationActivity. NOTE: This is the most straightforward way of sending data between two activities. See the example on using the starter pattern for a more robust implementation. OriginActivit...
// Compile a Uri with the 'mailto' schema Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts( "mailto","[email protected]", null)); // Subject emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Hello World!"); // Body of email emailIntent.putEx...
By using startActivityForResult(Intent intent, int requestCode) you can start another Activity and then receive a result from that Activity in the onActivityResult(int requestCode, int resultCode, Intent data) method. The result will be returned as an Intent. An intent can contain data via a Bundle ...
Opening with the default browser This example shows how you can open a URL programmatically in the built-in web browser rather than within your application. This allows your app to open up a webpage without the need to include the INTERNET permission in your manifest file. public void onBrowseCli...
Sometimes you may want to start a new activity while removing previous activities from the back stack, so the back button doesn't take you back to them. One example of this might be starting an app on the Login activity, taking you through to the Main activity of your application, but on logging out...
This example shows, how to start intent from browser: <a href="intent://host.com/path#Intent;package=com.sample.test;scheme=yourscheme;end">Start intent</a> This intent will start app with package com.sample.test or will open google play with this package. Also this intent...
Intents can be used to broadcast messages to other components of your application (such as a running background service) or to the entire Android system. To send a broadcast within your application, use the LocalBroadcastManager class: Intent intent = new Intent("com.example.YOUR_ACTION"...
4.0.3 Using a CustomTabsIntent, it is now possible to configure Chrome custom tabs in order to customize key UI components in the browser that is opened from your app. This is a good alternative to using a WebView for some cases. It allows loading of a web page with an Intent, with the added abil...
The String List passed as a parameter to the share() method contains the paths of all the files you want to share. It basically loops through the paths, adds them to Uri, and starts the Activity which can accept Files of this type. public static void share(AppCompatActivity context,List<Strin...
This pattern is a more strict approach to starting an Activity. Its purpose is to improve code readability, while at the same time decrease code complexity, maintenance costs, and coupling of your components. The following example implements the starter pattern, which is usually implemented as a st...
A Service is a component which runs in the background (on the UI thread) without direct interaction with the user. An unbound Service is just started, and is not bound to the lifecycle of any Activity. To start a Service you can do as shown in the example below: // This Intent will be used to star...
Share simple information with differents apps. Intent sendIntent = new Intent(); sendIntent.setAction(Intent.ACTION_SEND); sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send."); sendIntent.setType("text/plain"); startActivity(Intent.createChooser(sendIntent, get...
This example shows how to open a default dialer (an app that makes regular calls) with a provided telephone number already in place: Intent intent = new Intent(Intent.ACTION_DIAL); intent.setData(Uri.parse("tel:9988776655")); //Replace with valid phone number. Remember to add the tel: pr...
You can pass latitude, longitude from your app to Google map using Intent String uri = String.format(Locale.ENGLISH, "http://maps.google.com/maps?q=loc:%f,%f", 28.43242324,77.8977673); Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri)); startActivity(intent);
1. Passing integer data: SenderActivity Intent myIntent = new Intent(SenderActivity.this, ReceiverActivity.class); myIntent.putExtra("intVariableName", intValue); startActivity(myIntent); ReceiverActivity Intent mIntent = getIntent(); int intValue = mIntent.getIntExtra("intVa...
Starting a File Chooser Activity public void showFileChooser() { Intent intent = new Intent(Intent.ACTION_GET_CONTENT); // Update with mime types intent.setType("*/*"); // Update with additional mime types here using a String[]. intent.putExtra(Intent.EXTRA_M...
It is also possible to pass your custom object to other activities using the Bundle class. There are two ways: Serializable interface—for Java and Android Parcelable interface—memory efficient, only for Android (recommended) Parcelable Parcelable processing is much faster than serializable....
Like Getting a result from another Activity you need to call the Fragment's method startActivityForResult(Intent intent, int requestCode). note that you should not call getActivity().startActivityForResult() as this will take the result back to the Fragment's parent Activity. Receiving the result c...

Page 1 of 1