Scenario:
MainActivity (we'll call it activity A) has 3 fragments and starts activity B. Activity B then startActivityForResult (activity C). Problem is when setting result OK on activity C and calling onBackPress, startActivityForResult is getting called on Activity B but activity B is then closed after a few seconds.
Activity A -> Activity B -> Activity C (for Result), Result OK, finish
Then -> Activity B onActivityResult is called with Result OK but activity B finished and return to ActivityA which reload twice (I used Logcat and saw that onDestroy and onCreate was getting called twice for both Activity B and Activity A).
Find the following but didn't helped me a lot Activity is closed after onActivityResult is called
Tried to look at launchMode
Here is Manifest:
<activity
android:name=".activities.ActivityA"
android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden|screenSize"
android:theme="@style/AppTheme.NoActionBar"
android:windowSoftInputMode="stateHidden">
</activity>
<activity
android:name=".activities.ActivityB"
android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden|screenSize"
android:theme="@style/AppTheme.NoActionBar.Profile">
</activity>
<activity
android:name=".activities.ActivityC"
android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden|screenSize"
android:theme="@style/AppTheme.NoActionBar.Profile"
android:windowSoftInputMode="stateHidden|adjustPan">
</activity>
Here's the launches:
Activity A to Activity B:
intent = Intent(this@ActivityA, ActivityB::class.java)
intent.putExtra("user", user)
startActivity(intent)
Activity B to Activity C:
val intent = Intent(this@ActivityB, ActivityC::class.java)
intent.putExtra("user", user)
Activity C setting result OK and finishing:
setResult(Activity.RESULT_OK)
finish()
Screencast of the behavior: https://youtu.be/gMlH5iujoh0
Any help appreciated
Edit: Activity B onActivityResult
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == REQUEST_CODE_EDIT_PROFILE && resultCode == Activity.RESULT_OK) {
Timber.e("REQUEST_CODE_EDIT_PROFILE OK AND RESULT OK")
HelperTools(applicationContext).toastStatus(
getString(R.string.your_profile_has_been_updated),
Toast.LENGTH_SHORT,
ToastType.SUCCESS
)
populateData(user)
}
}
user
can you provide source of this class? If it is parcelable/serializable can you make sure if it parses correctly ? – RadekJ