I am trying to call a Fragment class from Activity using Intent. Is it possible to implement. Please provide your views.
Asked
Active
Viewed 2.3k times
3 Answers
4
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.

Blo
- 11,903
- 5
- 45
- 99
-
Thanks Fllo. I'll try this as you have mentioned. – Rajeev Sahu Mar 25 '14 at 14:19
-
If change it to fragment activity fragment manager not working – Nov 25 '14 at 05:58
-
Because you maybe need to use `getSupportFragmentManager` instead, @Eddie. – Blo Nov 28 '14 at 19:18
1
Fragment TargetFragment=new target_fragment();
FragmentTransaction transaction=getFragmentManager().beginTransaction();
transaction.replace(R.id.main_content,TargetFragment);
transaction.addToBackStack(null);
transaction.commit();

Davoud
- 2,576
- 1
- 32
- 53
-
Please add some explenation to your answer. Only showing code can be confusing for some people. – André Kool Sep 08 '16 at 10:30
0
Intent can not be applicable to Activity to Fragment So there Is Another method
getSupportFragmentManager().beginTransaction().replace(R.id.container,new DashBoardFragment()).commit();

saigopi.me
- 14,011
- 2
- 83
- 54