Live data from Hacker News

EasyMVP – Android library with annotation processing and bytecode weaving

github.com

11–14 of 14 posts

Re: EasyMVP – Android library with annotation processing and bytecode weaving

#11
post #9

Earlier quoted context omitted.

I don't believe it is as bad as BoorishBears says. Yes, configuration changes cause a tear down and recreation of your view/controller layers, but there are several patterns to deal with this cleanly (view controllers whose lifecycle spans multiple instance of a view is one of the more common, with the view instances detaching/attaching as they come and go). If you use a Flux like pattern for handling application dat…

Don't get me wrong, I don't mean to imply writing clean apps is impossible but I believe it's a fair assessment of the "state of the Union" for development. Even your comment kind of alludes to the mess: Yeah there's RxJava but it doesn't inherently solve the rotation issue because your Observables so you still need to persist the information needed to recreate them. And any long running tasks need a separate solutio…

I also think the Activity handling of configuration changes was a mistake; it should have only ever just been the view that was recreated.

However, I don't think that in the end it's that horrible, once you overcome the learning curve.

If your process is killed and the user returns to the app, you have to be able to restore state from either the Activity's saved instance state or from some other form of persisted state anyway - whether the current approach to configuration changes was in use or not makes no difference here, it's due to the entire approach of the OS to killing and restoring processes as required (and I believe this same approach is used on iOS and for UWP Windows applications).

For handling of async results - once the owner of an async operation is not tied to a single instance of a view and is instead tied to the overall lifetime of that part of the application (e.g. retained Fragment, a Conductor controller, or pretty much any other reasonably modern view composition library), it's pretty trivial to handle. You're guaranteed that nothing else will run on the main thread for the duration of an Activity destroy/recreate cycle, so you don't need to worry about being in some unknown state. If the view was recreated due to a configuration change, rebind your view model/s when it attaches. If you're being torn down because the user left the retained Fragment/Controller/whatever the operation was tied to, you'll receive an indication of that and you can either send a cancellation signal (e.g. unsubscribe), or if that's not possible, have an isDestroyed check where you receive your result to ignore it. If you're on the back stack and still alive but have no view (i.e. view NPE), don't bind your model immediately - update your view model, and the same code you use to rebind on view reattach will kick in when the user returns and a new view is created and attached.

Re: EasyMVP – Android library with annotation processing and bytecode weaving

#12
post #11

Earlier quoted context omitted.

Don't get me wrong, I don't mean to imply writing clean apps is impossible but I believe it's a fair assessment of the "state of the Union" for development. Even your comment kind of alludes to the mess: Yeah there's RxJava but it doesn't inherently solve the rotation issue because your Observables so you still need to persist the information needed to recreate them. And any long running tasks need a separate solutio…

I also think the Activity handling of configuration changes was a mistake; it should have only ever just been the view that was recreated. However, I don't think that in the end it's that horrible, once you overcome the learning curve. If your process is killed and the user returns to the app, you have to be able to restore state from either the Activity's saved instance state or from some other form of persisted sta…

I should add - I do think the learning curve is much worse than it should be, in part due to this.

It would be nice if Google provided some more recommendation and best practices & patterns around this. I have come across and had to work on plenty of code that handles this all very poorly.

Re: EasyMVP – Android library with annotation processing and bytecode weaving

#13
post #2

Can someone explain what these are? I'm not familiar with Android code.

The Android ecosystem is a few decades behind the rest of the development world for design patterns because, to frame it in web technology, every time you resize your window the entire browser restarts and its up to your page to restore its state (Activity/Fragment = Page) People were so busy fighting that mess in the early days they ended up writing a lot of shitty code. Then Android has reached where programming wa…

> every time you resize your window the entire browser restarts and its up to your page to restore its state

Wrong, it can be and often is disabled and windows are just resized without recreating of activities.

Re: EasyMVP – Android library with annotation processing and bytecode weaving

#14
post #13

Earlier quoted context omitted.

The Android ecosystem is a few decades behind the rest of the development world for design patterns because, to frame it in web technology, every time you resize your window the entire browser restarts and its up to your page to restore its state (Activity/Fragment = Page) People were so busy fighting that mess in the early days they ended up writing a lot of shitty code. Then Android has reached where programming wa…

> every time you resize your window the entire browser restarts and its up to your page to restore its state Wrong, it can be and often is disabled and windows are just resized without recreating of activities.

Disabling configuration changes is a naive hack (half the people who do it don't even disable every configuration so their apps break on something as simple as plugging in a keyboard with USB Otg or more commonly, tablets).

You're still supposed to handle all the configuration changes you disable yourself, and people rarely do. Disabling configuration changes is really for stuff like games where realistically the normal configuration change handling doesn't make sense and proper handling is as simple as resizing your surface or something.

And the window thing was part of the browser analogy, not the Android one, but ironically resizing an Android window can force an app to switch layouts causing a configuration change. Windows actually add even more complexity because now apps have to differentiate (to keep the analogy going) between when the user closes the browser and when the user clicks away from the browser (nuances with how the window features interact with stop vs pause which affect stuff like video playback apps)

Post reply on HN