Reputation: 1732
I am trying to call a Fragment class from Activity using Intent. Is it possible to implement. Please provide your views.
Upvotes: 4
Views: 23457
Reputation: 11978
Fragment
needs to be hosted by a FragmentActivity
, you can't add a fragment via an Intent
.
You need to create a FragmentManager
to add your fragment in the FragmentActivity
(or call another FragmentActivity
via an Intent
and add your fragment on it).
See this topic for more information: Add a Fragment to an Activity at Runtime.
Upvotes: 4
Reputation: 14908
Intent can not be applicable to Activity to Fragment So there Is Another method
getSupportFragmentManager().beginTransaction().replace(R.id.container,new DashBoardFragment()).commit();
Upvotes: 0
Reputation: 2933
Fragment TargetFragment=new target_fragment();
FragmentTransaction transaction=getFragmentManager().beginTransaction();
transaction.replace(R.id.main_content,TargetFragment);
transaction.addToBackStack(null);
transaction.commit();
Upvotes: 1