i am trying to use a custom ResultReciever from an intent into a intentService but i get this bizare error.
any ideas why?
Followed this guide in using resulReciever as callbacks
http://lalit3686.blogspot.co.uk/2012/06/how-to-update-activity-from-service.html
Here is my code from activity that starts service:
private void doNetworkInitCalls() {
intent = new Intent(getApplicationContext(), NetworkService.class);
intent.setAction(NetworkService.ACTION_GET_CITY_INFO);
intent.putExtra(NetworkService.EXTRA_LATLON, new LatLon(51.5073, 0.1276));
MyReciever reciever = new MyReciever(null);
reciever.setOnCityInfoRecieved(this);
intent.putExtra(MyReceiver.RESULT_RECEIEVER_EXTRA, reciever);
startService(getCityInfoIntent);
}
MyReciever class:
public class MyReciever extends ResultReceiver {
public static final String RESULT_CITY_INFO = "cityInfoData";
public static final String RESULT_RECEIEVER_EXTRA = "reciever";
public MyReciever(Handler handler) {
super(handler);
}
@Override
protected void onReceiveResult(int resultCode, Bundle resultData) {
super.onReceiveResult(resultCode, resultData);
}
}
IntentService:
public class NetworkService extends IntentService {
@Override
protected void onHandleIntent(Intent intent) {
if (intent != null) {
MyReciever reciever = intent.getParcelableExtra(MyReciever.RESULT_RECEIEVER_EXTRA); //fails on this line
}
}
What about this :
public class NetworkService extends IntentService {
@Override
protected void onHandleIntent(Intent intent) {
if (intent != null) {
ResultReceiver reciever = intent.getParcelableExtra(MyReciever.RESULT_RECEIEVER_EXTRA);
}
}
As CREATOR has not been redefined in MyReciever, it creates ResultReceiver instances. Just receive your ResultReceiver instance from the intent as it is, a ResultReceiver.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With