I am currently working on webservice calls from my Android application. The calls and results are handled within an IntentService. For now, I'm using a class (MyReceiver) which extends from ResultReceiver.
public class ResultReceiverWS extends ResultReceiver {
private Receiver mReceiver;
public ResultReceiverWS(Handler handler) {
super(handler);
}
public void setReceiver(Receiver receiver) {
mReceiver = receiver;
}
public interface Receiver {
public void onReceiveResult(int resultCode, Bundle resultData);
}
@Override
protected void onReceiveResult(int resultCode, Bundle resultData) {
if (mReceiver != null) {
mReceiver.onReceiveResult(resultCode, resultData);
}
}
}
I pass from the Activity which implements MyReceiver.Receiver the instance of the class in a bundle like above code :
MyReceiver receiver = new MyReceiver (new Handler());
receiver.setReceiver(this);
Intent call = new Intent(getApplicationContext(), ClientWS.class);
call.putExtra(RECEIVER, receiver);
call.putExtra(ACTION, MYMETHOD);
startService(call);
The problem is that receiver is attached to the Activity thread, if activity is killed, re-created (by turning screen or whatever), receiver points in no man's land ...
So, my question is how to handle this cases. I've thinked about BroadcastReceiver but I'm not sure about that.
Any suggestions are welcome here.