How to pass data from activity to fragment in android

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/

 

 

 

 

 

. . .

Comments (4)

Add Your Comment

  • syafiq
    Thank you very much
  • MANINDER SINGH BADSHAH
    Thanks a lot Bro!
  • Haris Ahmed
    Thanks a lot 😀 I knew bundles are used but didn’t know this was this much simple.
    • Aman Gupta
      You are most welcome @Haris
  • css.php
    Hire Us!
    Brief us about your requirements and we'll get back to you.
    Woo! Hooy!
    We have just recieved your project brief and our expert will contact you shortly.
    Send Again
    Close