I have a net service in my app, for now it doesn’t matter if it’s a thread in the Application context or a service, what does matter is i have some trouble getting response properly.
The service is working, and i do get responses, right now i work with the observer design patter which is a bitch in android 🙁 i have to remove the listener in on destroy and then check the network if it is all ready finished and handle different scenarios.
I want to change my approach, but i’m not sure what’s the right android way, it seems like activities are made for polling which is bad for my architecture and error prone :-(.
I thought of the folowing two methods but non seem to give me a real solution:
- create a braodcast receiver that
will send a broadcase with a flag if
response or error arrived from the
net, it’s apt to the activity to
poll the right data and handle. i do
wonder about this since if i
register for broacast i basically
have to remove the listener in on
pause, so i CAN miss a broadcast,
then it’s back to check the net
state in onCreate, same like what
i’m doing now – sucks… - register the activity that whats an event and sent it an intent using startActivity but here if the activity is in on pause or stop i’ll bring it to the front, i don’t want this kind of behavior, i only want that the activity will get the event no matter what, and starting to wonder if there’s a way to do that.
The landscape\portrait event are killing me, any way out of it ?
i discovered the following:
landscape\portrait events myself and
then i eliminate 90% of the problem
if i get new intent that doesn’t kill my app (depends on the intent) i get it in onNewIntent() method. i can put some init functions that are dependant on those values in a seperate init function that gathers them all to share them between onCreate and onNewIntnet.