My app uses the startActivityForResult
pattern. To account for the fact that I am calling startActivityForResult
from a fragment I unmask the request code.
MyFragment.java
Intent intent = new Intent(context, LoginActivity.class);
startActivityForResult(intent, 1);
MainActivity.java
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
int unmaskedRequestCode = requestCode & 0x0000ffff;
if (unmaskedRequestCode == 1) {
success();
}
}
The issue I am having is that this code works perfectly fine when my build.gradle
used
implementation 'androidx.appcompat:appcompat:1.2.0'
However, when I upgraded to
implementation 'androidx.appcompat:appcompat:1.3.1'
I started getting requestCodes that seemed random. In my testing it looked like you could work around this by instead calling startActivityForResult
from the parent getActivity().startActivityForResult(intent, 1);
. However, I would prefer to understand the issue better before I start changing code to account for this new version.
What changed in appcompat that causes the newer version to give different request codes than before?