-2

Im creating an application which will contain a Viewpager.

I haven't decided whether I want to use fragments or activities.

If i were to use fragments, I would have to use nested fragments, which is only available for mobile users with API level 17 and higher. According to this dashboard, I won't be able to reach 29% of the market: https://developer.android.com/about/dashboards/index.html

If I were to use Activities, it would take more work, but I would be able to reach the whole market. It would also be easier for me since I haven't worked with fragments at all since I'm relatively new to Android programming.

Should I use activities or fragments? And why?

3 Answers3

4

Hie, As per my concern, using a view pager with fragments will be more feasible and useful compared to activities or activity transitions. Fragments have their own life cycle and the best part is you can reuse a fragment multiple time in your activity/parent activity class. ViewPager with PagerSlidingTabStrip would be a good one to use for your project and go further. It requires a minimum API level 14 (Android 4.0 and higher), through which you will be able to reach/target more than 70% of today's devices. This link can help you up. https://guides.codepath.com/android/Sliding-Tabs-with-PagerSlidingTabStrip

Ravi Kabra
  • 1,284
  • 1
  • 11
  • 17
0

If you are thinking about whole android market you should use activity but if you want to catch not all but most of the people using android you should use fragment.

If i be in your place i will use fragment because today most of the people using API 19 as per google research, so that would be better option and fragment is also easier than activity in your concept as you have told "activity will make it more complex".

0

Fragments are better and faster than activities.

They allows you multiple things like adding / replacing fragments , you can also add your custom animation between fragments and much more...

Check out Fragments here http://developer.android.com/guide/components/fragments.html