Can I use a fragment as an activity? I have created a fragment but I want it have fuction like an activity so I use fragment extend fragmentactivity. However, I had a navigation drawer with fragments. When I change to 'extend fragmentactivity', my code has problem? Please show me the way.
Asked
Active
Viewed 289 times
-1
-
IMO this question is too broad in scope for StackOverflow. You don't really have a concrete problem to debug, you have a fundamental misunderstanding/unfamiliarity with Android, Activities, and Fragments. That's fine; everyone starts from zero, but a different resource is probably a better bet for you. – Ben P. Nov 13 '18 at 17:52
1 Answers
1
That's not what FragmentActivity is used for. FragmentActivity is used to add the support library API for fragments and loaders to Activity. It does not turn a fragment into an activity.
If you have an existing fragment and want to use it as an activity, it's probably easiest to wrap the fragment in a very lightweight activity. The activity won't have much logic except for onCreate() where you'll set a layout that contains a fragment tag.

Greg Moens
- 1,705
- 8
- 15