How Send Data from Activity to Fragment in Android?
Contents

How can we convert data from activity to fragment?

How to pass data from Activity to Fragment

  1. Bundle bundle = new Bundle();
  2. bundle. putString(“params”, “My String data”);
  3. MyFragment myObj = new MyFragment();
  4. myObj. setArguments(bundle);

30 дек. 2016 г.

How send data from fragment to activity in Android?

To allow a Fragment to communicate up to its Activity, you can define an interface in the Fragment class and implement it within the Activity. The Fragment captures the interface implementation during its onAttach() lifecycle method and can then call the Interface methods in order to communicate with the Activity.

Marcus Vance

Marcus Vance

Cybersecurity & Digital Privacy Researcher

Marcus Vance is a cybersecurity auditor and technology writer dedicated to educating the public about online safety, data privacy regulations, enterprise security, and emerging cyber threats.

Share this article
Twitter Facebook Pinterest