Navigating and sending data from activity to fragment

时间:2015-07-31 19:53:04

标签: android android-fragments navigation-drawer android-fragmentactivity

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.

2 个答案:

答案 0 :(得分: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();

答案 1 :(得分: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