I have 2 activities: B and C.
B starts C, and then by user action, C finishes and I have A again.
Here is the code that takes the user from B to C
public void goToC(View v) {
Intent intent = new Intent(this, C.class);
intent.putExtra("STUFF", stuff);
startActivityForResult(intent, 1);
}
Here is the code in C that passes data back to B
long rowsUpdated = myModel.updateStuff(this, stuff);
if (rowsUpdated == 1) {
Intent intent = new Intent();
// put the data in the intent
intent.putExtra("STUFF", stuff);
// set the flags to reuse B
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_SINGLE_TOP);
// set result code to notify the ItemEntriesActivity
setResult(1, intent);
// finish the current activity i.e. C
finish();
}
Here is the code in B that receives the above data
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
if (intent != null) {
switch (resultCode) {
case 1:
// Update the class variable, so that onResume() gets the updated value
stuff = intent.getExtras().getParcelable("STUFF");
break;
default:
break;
}
}
}
My problem is that this code works correctly, but whenever I go from B to C, the onStop()
on B is called. I don't have any code that calls finish()
on B. This forces the B.onCreate()
to be called everytime, and makes my app slow. I also stried putting android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
in both the activities in my Manifest, but no luck. I have spent 2 days on this, and near the end of my wits. Any help is appreciated.