Is it bad practice to have only one action in your Android app that uses fragments?

I am wondering if this is not a “no” in the Android community.

My application has only MainActivity and uses ViewPager and TabLayout to navigate fragments in the application.

The only problem that I see is if the user clicks the "Back" button, she will exit the application and the application will not remain active, as it would be by pressing the "home" button.

Your thoughts?

+6
source share
1 answer

Good question. A few months ago I was thinking about myself.

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

You can manage your fragments from one action, since all fragments are independent of each other.

Limitation:

One fragment should never speak directly to another fragment, you need to go through parental activity.

Only some error points:

  • You need to find out all the details about the fragment.

  • You need to control the order of the fragments.

  • It adds lbit complexity to the code.

One action and all other fragments

+1
source

All Articles