17

I got this exception

"java.lang.IllegalStateException: Can not be called to deliver a result" 

And didn't immediately understand why. Below is my answer to why this happened, maybe this helps someone.

issamux
  • 1,336
  • 1
  • 19
  • 35
Divisible by Zero
  • 2,616
  • 28
  • 31

1 Answers1

38

I had called finishAffinity() after having set a result code. Android was complaining that it will never be able to deliver the result when calling finishAffinity().

Solution: either don't set the result before calling finishAffinity(), or set the result again before calling finishAffinity() but this time with Activity.RESULT_CANCELED as the result code:

setResult(Activity.RESULT_CANCELED);
finishAffinity();
Divisible by Zero
  • 2,616
  • 28
  • 31