Best way to Send data between activitiesHow to send data between activities in android
Programming Guru
Android | How to send data from one activity to second activity This tutorial aims to tell and show about how to “Send the data from one activity to second activity using Intent”. In this Example, we have two activities, activity_first which is the source activity and activity_second which is the destination activity. We can send the data using putExtra() method from one activity and get the data from the second activity using getStringExtra() methods.
In this Example, one EditText is used to input the text. This text is sent to the second activity when the “Send” button is clicked. For this, Intent will start and the following methods will run: putExtra() method is used for send the data, data in key value pair key is variable name and value can be Int, String, Float etc. getStringExtra() method is for getting the data(key) which is send by above method. according the data type of value there are other methods like getIntExtra(), getFloatExtra()
Sending simple data to other apps
Android uses Intents and their associated extras to allow users to share information quickly and easily, using their favorite apps.
Android provides two ways for users to share data between apps:
The Android Sharesheet is primarily designed for sending content outside your app and/or directly to another user. For example, sharing a URL with a friend.
The Android intent resolver is best suited for passing data to the next stage of a well-defined task. For example, opening a PDF from your app and letting users pick their preferred viewer.
When you construct an intent, you must specify the action you want the intent to perform. Android uses the action ACTION_SEND to send data from one activity to another, even across process boundaries. You need to specify the data and its type. The system automatically identifies the compatible activities that can receive the data and displays them to the user. In the case of the intent resolver, if only one activity can handle the intent, that activity immediately starts. Why you should use the Android Sharesheet
We strongly recommend using the Android Sharesheet to create consistency for your users across apps. Apps should not display their own list of share targets or to create their own Sharesheet variations.
The Android Sharesheet gives users the ability to share information with the right person, with relevant app suggestions, all with a single tap. The Sharesheet can suggest targets unavailable to custom solutions, and with consistent ranking. This is because the Sharesheet can take into account information about the app and user activity that is only available to the system.
The Android Sharesheet also has many handy features for developers. For example, you can:
Find out when your users complete a share and to where
Add your own custom ChooserTarget and app targets
Provide rich text content previews starting in Android 10 (API level 29)
Exclude targets matching specific ComponentNames
Using the Android Sharesheet
For all types of sharing, create an intent and set its action to Intent.ACTION_SEND. In order to display the Android Sharesheet you need to call Intent.createChooser() , passing it your Intent object. It returns a version of your intent that will always display the Android Sharesheet. Sending text content The most straightforward and common use of the Android Sharesheet is to send text content from one activity to another. For example, most browsers can share the URL of the currently-displayed page as text with another app. This is useful for sharing an article or website with friends via email or social networking. Here's an example of how to do this: ... https://www.youtube.com/watch?v=PpWQwhJ33WI
28219934 Bytes