0

I created a navigation drawer. Now,navigation drawer requires all fragments. I want to send some information and move to this fragment which contains drawer from an activity. How do I implement this ? I am using Intent(activityclass.this,fragment.class) for navigation and putExtra for sending data. But the app crashes.

Nikhil Khurana
  • 422
  • 1
  • 5
  • 12

2 Answers2

0

Fragments are not loaded using Intent. You need to use FragmentManager:

 Fragment fragment = new MyFragment();
 FragmentManager fragmentManager = getFragmentManager();       
 fragmentManager.beginTransaction().replace(R.id.container,fragment).commit();
0

your approach needs some modification i would like to refer the below links for better ways

official tutorial

Some good practises for your app communication

raktale
  • 465
  • 3
  • 12