For those who cbb tldr:...
Solution is on github, because I don't know yet how to post nice CODE in blogger.
https://github.com/k-gintaras/lifecycle-networking-example
For very curious:
I struggled for very long to find solution to my problem, it turns out I found it long ago, but "recommendations" of good practices kept me turning away from it. I feel it is a must to write this for those who might feel the same.
I needed my app to send request, receive response and to be able to use it without requesting for the same thing multiple times.
I googled how to send simple network request and used our old friend Java code.
After a lot of little problems like can't run networking on main thread and therefore display the result in activity were solved with AsyncTask using interface everything seemed to work nicely. But when my friend rotated test device, a super galactic monster of a problem appeared saying "HELLO, MY NAME IS ANDROID APPLICATION LIFECYCLE!".
So much to tell, so much struggle, 4 totally different rewrites. Some of them included saving responses to database, then each time activity restarts, checking sqlite database. Some of them included saving network states in bundle and trying to restore with savedInstanceState.
Googling and googling...
Lots of solutions show using singletons.
Googling singletons...
...bad practice...
Can't find solution without singleton.
Googling and googling...
There is a huge monstrocity that might be worth learning, it's called Retrofit.
But example solutions still include singletons even with Retrofit.
Googling and googling...
Duck it...
Let it be singleton.
Googling...
Hello (CLINTON TEEGARDEN, 2016) at https://www.captechconsulting.com/blogs/a-mvp-approach-to-lifecycle-safe-requests-with-retrofit-20-and-rxjava
A code a bit confusing and with little mistakes, but WOW, it WORKS!!!
Modified it and hopefully improved it a bit.
Forget trying to ALWAYS do good practices, just solve your problem, finish product and when you become rich and amazing resourceful programmer, you can try creating perfect code poetry on your spare time.
Solution is on github, because I don't know yet how to post nice CODE in blogger.
https://github.com/k-gintaras/lifecycle-networking-example
Sincerely,
Ubaby