8

I'm wondering if this is a 'no no' in the Android community.

My app just has a MainActivity and uses a ViewPager and TabLayout to navigate across the fragments in the app.

The only problem I see is if the user presses the back button, it will exit the app and the app will not stay active like it would by pressing the home button.

Your thoughts?

God Usopp
  • 331
  • 1
  • 6
  • 18
  • 1
    No, no more than it is a "bad practice" to have a Web app that consists of a single page and performs DOM manipulations to change up its contents. There are plenty of reasons to have more than one activity. None are required for arbitrary apps. – CommonsWare Nov 28 '15 at 13:43
  • @CommonsWare....you are right, there is one limitation again:One fragment should never talk directly to another fragment, you have to go through the parent activity – Sanket Prabhu Nov 28 '15 at 14:03
  • Possible duplicate of [One Activity and all other Fragments](http://stackoverflow.com/questions/12154505/one-activity-and-all-other-fragments) – Sanket Prabhu Nov 28 '15 at 19:03

1 Answers1

6

Nice question bro, Few months back I was thinking in sameway.

You are 100% right, you can do it without any trouble, it only depend on your project and what do you want to achieve.

You could control your fragments from a single activity, beacause all fragments are independent of each other.

The limitation is :

One fragment should never talk directly to another fragment, you have to go through the parent activity

Only some imp points are:

  1. You need to learn all details about fragment.

  2. You have to manage the order of the fragments.

  3. It add lbit complexity in code

One Activity and all other Fragments

Community
  • 1
  • 1
Sanket Prabhu
  • 2,232
  • 3
  • 20
  • 33