"My app crashes with NullPointerException when the user rotates the phone while a network request is happening"
“My app crashes with NullPointerException when the user rotates the phone while a network request is happening. Do you have any plans to fix?” - Jake Bhagwan Wharton.
Dealing with Activity lifecycles can be difficult, especially when working with long running background operations like network calls. But this complexity can greatly be reduced by following a design pattern that is independent of all lifecycles. One such pattern is using a data provider as the single source of truth.
- Designing “auto-updating” UIs using reactive programming.
- Retaining app state across Activity configuration (e.g., orientation) and process deaths.
- Creating fire-and-forget network calls that affect the UI without caring to unsubscribe them on Activity stop/destroy.
- Designing an offline-first code archiecture.
- Exploring LiveData introduced at Google IO 2017.
You must have spent atleast a couple of years banging your head on walls while dealing with Android lifecycles and asynchronous jobs. A basic knowledge of RxJava or reactive programming in general will also be nice to have, but is not necessary.
Saket is passionate about building personal, contextual software that is always aware of the user’s intentions. He started developing Android applications 4 years ago, when Ice Cream Sandwich was still the shiny new thing. He strives for perfection, especially when it comes to user experience. He will often tweak animations down to the millisecond to make them feel more natural.
He works with Uncommon.
- SQLBrite: https://github.com/square/sqlbrite
- The introduction to Reactive Programming you’ve been missing: https://gist.github.com/staltz/868e7e9bc2a7b8c1f754
- LiveData: https://developer.android.com/topic/libraries/architecture/livedata.html