How to pass data from activity to fragment in android

Updated 30 December 2016

Save

We Know how to send the data from the Activity to another Activity. But what if we want to send the data from Activity to fragment?

So the technique is very similar to send data to activity. For sending the data to fragment we use the Bundle.

Bundles: A mapping from String keys to various Parcelable values. They are generally used for passing data between various Android activities and fragments.

How to pass data from Activity to Fragment

There are simple blocks of code to pass data from the Activity to fragments.

Step 1: Passing the data from activity to fragment,

Step 2: Receiving the data to the fragment,

 

Source: https://developer.android.com/

 

 

 

 

 

author
. . .

Leave a Comment

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


8 comments

  • syafiq
  • yusunglee
  • MANINDER SINGH BADSHAH
  • Haris Ahmed
    • Aman Gupta (Moderator)
  • Pitam
  • Merry
    • anchit (Moderator)
  • Start a Project


      Message Sent!

      If you have more details or questions, you can reply to the received confirmation email.

      Back to Home