TomBomb TomBomb - 5 months ago 61
Android Question

Android - startActivityForResult immediately triggering onActivityResult

I am launching activities from the main activity in my app using the call

startActivityForResult(intent, ACTIVITY_TYPE)
, and they are all working but one.

This one, when called, launches the activity as desired, but in the log I can see that
onActivityResult()
is immediately being triggered. The activity shows up but
RESULT_CANCELED
is immediately returned to
onActivityResult()
.

I then interact with the activity, press a button which calls
finish()
, and
onActivityResult()
is not called the time (because apparently a result has already been returned).

Does this make sense to anyone? Has anyone seen this behavior before?

Answer

You can't use startActivityForResult() if your activity is being launched as a singleInstance or singleTop.