6

While discovering Android libraries and frameworks, I came across Square's blog post on Flow and Mortar. The author states that some of the motivations for developing Flow and Mortar was because

... Offscreen fragments mysteriously being brought back to life at odd moments
... No direct control over animation

I am having trouble understanding what the author means. Can anyone elaborate these two pain points the author speaks of?

rds
  • 26,253
  • 19
  • 107
  • 134
Some Noob Student
  • 14,186
  • 13
  • 65
  • 103
  • 3
    I don't have an answer, but you should consider what Jake Wharton, a Square developer, has to say about the Flow. https://twitter.com/koush/status/440279806182039553 – Krylez Aug 20 '14 at 20:03
  • Thanks for the link, it was a resourceful read. Unfortunately it does not shed light on the pain points of using Fragments, which is the main focus of this question. – Some Noob Student Aug 26 '14 at 19:54
  • Not a credible source, therefore just a comment - offscreen fragments seem to have issues: http://stackoverflow.com/questions/17396310/updating-offscreen-fragments-in-a-viewpager - don't know if still the case as question is from 2013 but maybe a reference for mentioning it as motivation. – matthias_h Sep 03 '14 at 23:00

1 Answers1

6

I recommend you to read Square's new blog post. It clearly describes fragments' problems due to its' complex livecycle, implementation dependent errors, transactions and creation magic. The key idea is that There is no need for new APIs; everything we needed was there from the very beginning: activities, views, and layout inflaters.

Considering your questions:

Offscreen fragments mysteriously being brought back to life at odd moments

Quote from post: If you ever found yourself with a stale unattached fragment recreated on rotation, you know what I'm talking about. ...when restoring the activity instance state, the fragment manager may try to recreate an instance of that fragment class using reflection.

No direct control over animation

About fragment transactions: ...committing a transaction is async and posted at the end of the main thread handler queue. This can leave your app in an unknown state when receiving multiple click events or during configuration changes.

Kirill Boyarshinov
  • 6,143
  • 4
  • 33
  • 29