Android App Development
iOS App Development
Cross Platform App Development
Hire on-demand project developers and turn your idea into working reality.
Big thanks to Webkul and his team for helping get Opencart 3.0.3.7 release ready!
Deniel Kerr
Owner and Founder. Opencart
Top Partners
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.
Parcelable
There are simple blocks of code to pass data from the Activity to fragments.
Step 1: Passing the data from activity to fragment,
Bundle bundle = new Bundle(); bundle.putString("params", "My String data"); // set MyFragment Arguments MyFragment myObj = new MyFragment(); myObj.setArguments(bundle); 12345 Bundle bundle = new Bundle();bundle.putString("params", "My String data");// set MyFragment ArgumentsMyFragment myObj = new MyFragment();myObj.setArguments(bundle);
Step 2: Receiving the data to the fragment,
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (getArguments() != null) { mParam1 = getArguments().getString("params"); } } 123456 public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (getArguments() != null) { mParam1 = getArguments().getString("params"); } }
Source: https://developer.android.com/
Your email address will not be published. Required fields are marked*
Name*
Email*
Save my name email and website in this browser for the next time I comment.
The code explained in the article itself explains the approach.
We use cookies to personalize your experience. By continuing to visit this website you agree to our use of cookies. Learn more about privacy policy
Webkul is a truly trusted and supported IT Company to develop business ideas for e-commerce. They provide professional support after deploying the solution to production and be responsible to act for fixing the reported issues or system errors. We highly encourage to deal with Webkul for business development.
Hussein Zawia
Co-founder, 24Dokan
USA
India
Global
Name
Email
Enquiry or Requirement
If you have more details or questions, you can reply to the received confirmation email.