• About
  • Advertise
  • Privacy & Policy
  • Contact
Tech News, Magazine & Review WordPress Theme 2017
  • Home
    • Home – Layout 1
    • Home – Layout 2
    • Home – Layout 3
    • Home – Layout 4
    • Home – Layout 5
  • Review
  • Gaming
  • Gear

    Trending Tags

    • Best iPhone 7 deals
    • Apple Watch 2
    • Nintendo Switch
    • CES 2017
    • Playstation 4 Pro
    • iOS 10
    • iPhone 7
    • Sillicon Valley
  • Computers
  • Applications
  • Security
No Result
View All Result
  • Home
    • Home – Layout 1
    • Home – Layout 2
    • Home – Layout 3
    • Home – Layout 4
    • Home – Layout 5
  • Review
  • Gaming
  • Gear

    Trending Tags

    • Best iPhone 7 deals
    • Apple Watch 2
    • Nintendo Switch
    • CES 2017
    • Playstation 4 Pro
    • iOS 10
    • iPhone 7
    • Sillicon Valley
  • Computers
  • Applications
  • Security
No Result
View All Result
Overflow Archives
No Result
View All Result

Share Data Using Intent Across Activities in Android

by
Home Android
Share on FacebookShare on Twitter

In this read, we will see, how to share data using intent across different activities in Android app development. This post will help you to understand how the data is shared between activities inside the Let’s see how the data can be shared across the activities using Intent.

What is Intent in Android

The intent is a simple message object that is used for communicating between the Application components, like activity, content providers and broadcasting receivers and services. By using intent, data can be shared between the activities.


Also Read: Android SearchView in ActionBar— Androidx and Kotlin


How to call an Intent

In Android application development, the intent can be called using the startActivity() method. Using this method the intent is passed as a parameter while calling this we can share the data to the different activities. It supports all types of primitive data types and also it helps to share a data class object too.

Type of data allowed to share

The intent allows the application to share any data type from an activity to another activity by using  intent.putExtra(Key, value) method.
By this way we can share the data to the different components and activities.

To get the data in activity the intent extra should be getting based on the data type, if the value is a string then intent.getStringExtra(key). Likewise, we can receive the data. If the shared data is parcelable then use getParcelableExtra(key) followed by the data type.

Methods used in data sharing

The extras shared in intent can be verified by hasExtra(key). This will return a boolean value.  If the extra is attached to the intent the data returned upon using getExtra(), if not null will be returned.

note: whenever getting the data from intent, it is a best practice to check for the availability of the data for the requesting key.

For more information on this please visit the developer’s documentation page for an updated one. That information is available on Content/Intent.

How to send and receive data

For example please look at the below code for how to send and receive the data.

Let’s consider we’re sharing a string extra through the intent. Here is how can we receive the data in NextActivity class.

Other ways to send data

Similarly, the data between different activities can be shared using a static variable in the receiver class/activity. In this way, we don’t need the intent to share the extras/bundle with the receiver activity.

We can assign the data to the static variable before we start the particular activity/class. Also accessing the data in the receiver class is too easy in this way.

Limitations on sharing data

However, the intent is allowed to share the data to the activities and components, there are few limitations to it. For example, if we share a large amount of data through it it may result in an application crash.

As the memory for data sharing in the mobile application is limited sharing large data may arise an issue. So it’s better to use another method of data sharing. Like assigning a static variable. API call and other memory handlers.

Tags: andoird data sharingandroidandroid codeandroid developmentandroid intent

Next Post
overflowarchives.com - Android gradle SHA key

How to generate Android studio SHA key

Comments 1

  1. Pingback: How to generate Android studio SHA key - Overflow Archives

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recommended.

Unity 3D Game Development – Getting Started!

Unity 3D Game Development – Getting Started!

Parse Color Runtime In Unity 3D - Thumbnail

Change Color in Runtime – Unity 3D Tutorial

Trending.

How to Create circular progress bar in Unity 3D with rounded edge

Progress bar in Unity 3D

How to Create Progress bar in Unity 3D

Unity Gradient Effect UI Design Without Scripting | Simple Gradient Effects in Unity 3D

Unity Gradient Effect UI Design Without Scripting | Simple Gradient Effects in Unity 3D

Create Switch button UI in Unity 3D - overflow archives

Create Switch button UI in Unity 3D

Android Developer Options – Debugging Mode Options Explained – Part – I

Android Developer Options – Debugging Mode Options Explained – Part – I

Overflow Archives

© 2023 OverflowArchives.

Navigate Site

  • About
  • Advertise
  • Privacy & Policy
  • Contact

Follow Us

No Result
View All Result
  • Home
  • Review
  • Apple
  • Applications
  • Computers
  • Gaming
  • Gear
    • Audio
    • Camera
    • Smartphone
  • Microsoft
  • Photography
  • Security

© 2023 OverflowArchives.