Check Mobile App
Read now
Start a Project

How to pass data from activity to fragment in android

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/

 

 

 

 

 

. . .

Leave a Comment

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


8 comments

  • syafiq
    Thank you very much
  • yusunglee
    Simple
    Thx
  • 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 (Moderator)
      You are most welcome @Haris
  • Pitam
    thanks
  • Merry
    Hi, can you show example on how to pass data from one fragment to another fragment? Thank you!
    • anchit (Moderator)
      Firstly, you will need to put everything in a bundle.
      Then you can pass on the bundle in the arguments while adding or initializing the fragment.

      The code explained in the article itself explains the approach.

  • css.php

    Great Product, Great Team, and Great Support Service. And if you want to add more features to the product, they can submit any idea that comes to your mind. They really care about their clients and we are really happy and honored to deal with Webkul.

    Osama
    Talk to Sales

    Global

    Live Chat
    Start a Project

      Message Sent!

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

      Back to Home