1

I have one doubt and want to clear some points regarding the Activity holding multiple fragments.

I have 10 fragments attached with one Activity (HomeActivity.java); this activity contains one navigation drawer and tool bar with multiple icons like search, add, remove, back button etc.

The structure which I am following is below,

User clicks any item from navigation drawer, I am loading the fragments,

fragmentManager.beginTransaction().replace(R.id.fragment_container, fragmentToLoad, tagFragment).addToBackStack(tagFragment).commit();

fragmentToLoad -> fragment name, tagFragment -> tag to that particular fragment.

I am changing the title name, toolbar based according to the fragments in HomeActivity itself.

My navigation drawer items are having one fragment only and get replaced in fragment_container but one thing is also there, that these fragment are also having inner sub-fragments too.

In the start, I said that there are 10 fragments, those 10 fragments are navigation drawer items. There are many inner framgents.

Now, the inner fragment's click listeners and other activities I am maintaning in HomeActivity.java itself using interfaces(Listeners).

SO, some times I am getting warning "There is a lots of work going on main thread".

I understand that there is lots of activities going on HomeActivity.java.

Please tell me this architecture is wrong or is there any solution.

Custadian
  • 845
  • 1
  • 11
  • 37
  • You can use fragments like this... but it's generally not recommended, because you end up with a really bloated "super-activity". Fragments were more a solution to help with tablet development at first - to avoid having to rewrite or duplicate gigantic sections of code to make a tablet layout. Consider separating out your fragments into activities based on use cases. – Zadrox Jun 03 '15 at 07:49
  • You should consider moving from fragments to custom views. I don't know if warnings you are getting are connected to your apps architecture, but overusing fragments surely doesn't help. https://corner.squareup.com/2014/10/advocating-against-android-fragments.html – pawelo Jun 03 '15 at 07:50
  • Also, if you have some time, take a peek at the Google IO 2014 iosched source code - https://github.com/google/iosched. It's a good example of how to organize an android app. – Zadrox Jun 03 '15 at 07:57

1 Answers1

0

I wouldn't say that your architecture is WRONG. Instead, I would say that by using single central activity to handle so many fragments, you are making maintaining and debugging that activity very difficult for yourself.

As far as the warning message is concerned, it depends upon the number of frames skipped (something that is printed before 'There is a lots of work going on main thread' in the log). I believe if the number is ~ 100 then it really shouldn't be a matter of grave concern. Kindly go through this SO answer for complete explanation! Hope that helps.

Community
  • 1
  • 1
Uncaught Exception
  • 2,149
  • 18
  • 25