3 ms·
It's gotten better, but check my comments from some time ago: https://news.ycombinator.com/item?id=8329034 https://news.ycombinator.com/item?id=8329034 https:/
by cel1ne 10y ago
It's gotten better, but check my comments from some time ago:
https://news.ycombinator.com/item?id=8329034 https://news.ycombinator.com/item?id=8329034
https://news.ycombinator.com/item?id=9476547 https://news.ycombinator.com/item?id=9476547
Generally: bad inheritance, bad separation of concern, unidiomatic java (I think much of it was automatically converted from C++), overcomplicated classes and just so many wtf-moments I had.
Example: You want to store state.
1. In standard activities you have this really nice method "onSaveInstanceState" where you can save state to a "Bundle". And "onCreate" where you are handed a bundle to restore. You write the logic for doing that and should be done.
2. Then you learn that "onSaveInstanceState" isn't actually called when stopping an app, only when rotating the screen, so you have to save your state elsewhere. In onStop for example, sounds nice.
3. onStop doesn't take a "Bundle". Hm… ok let's see save it to disk.
4. Oh, Bundle isn't meant to be serialised because the internal format is allowed to change, so you have to write serialisation again after all. Ok, "Bundle" is out.
Let's use json and be done with it.
5. But for some reason it sometimes doesn't work. Turns out "onStop" only sounds like it's being called when your app stops. It's actually not guaranteed to be called, so you have to use "onPause".
This is just one example of many where things could be more aptly named, better documented and so on.
- Drdrdrq 10y agoThanks for the explanation. I guess I never even looked at the names of these callbacks because I just followed the app lifecycle diagram - yeah, I agree, the names could be much better.
- cel1ne 10y agoWell nothing in the diagram here says anything about onStop being not guaranteed: https://developer.android.com/training/basics/activity-lifecycle/stopping.html https://developer.android.com/training/basics/activity-lifec...