FireFly3000 FireFly3000 - 1 month ago 11x
Android Question

setResult(int, intent) not working in Android

I have tried many solutions now. However, I cannot get the compiler to approve setResult(int, intent) in my activity. I have started the activity with startActivityForResult.

Can you see the problem?

My code looks like this:

networkServiceMessageReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
//TODO: Implement the methods that should be executed on validation results

PrinterData printerData = intent.getParcelableExtra(NetworkService.VALIDATE_PRINTER_RESULT);

if(printerData != null)
Intent data = new Intent();
data.putExtra(VALIDATE_PRINTER_RESULT, printerData);

setResult(RESULT_OK, data);




Android Studio gives this error:
enter image description here


BroadcastReceiver has its setResult method, which takes three parameters, not two, and you probably want to use setResult from the class Activity. Reference it like:

ActivityName.this.setResult(RESULT_OK, data);

if the BroadcastReceiver is declared inside an Activity