I have an activity that I'm starting:
Intent intent = new Intent(this, CreateItemDetailsActivity.class);
if(storeId != null) {
intent.putExtra(Identifiers.STORE_ID, storeId);
}
intent.putExtra(Identifiers.ITEM_NAME, name);
intent.putExtra(Identifiers.ITEM_DESCRIPTION, description);
startActivity(intent);
This works, but now I need to return data to the original activity, so I change startActivity
call to:
startActivityForResult(intent, CREATE_ITEM_RESULT);
(CREATE_ITEM_RESULT
is just a random integer number 63463657 I made up)
However, my app crashes without neither onCreate
methods (I've implemented and put a breakpoint in both) being called:
Uncaught exception in thread main: java.lang.IllegalStateException: Could not execute method for android:onClick
android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:389)
(the code is called in a button click handler, hence onClick
)
I've seen App crashes when calling startActivityForResult which has the same problem but the accepted answer suggests removing a line, recipe.setFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);
, which I don't have.
Why am I getting a crash on startActivityForResult
while startActivity
works perfectly?
(My min SDK level is 16, target and compile SDK levels are 27, and I'm running Android 8.1 emulator)