I have two activities, let’s call them A and B.
A is an activity that can be started from two places in the app. I want to be able to know if A was started from place 1 or 2, so in B I call A like this:
Intent i = new Intent(B.this, A.class);
i.putExtra("code", code);
startActivityForResult(i, code);
(code is an int with the value 1.)
In the onCreate method of A I do this:
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
Intent i = getIntent();
Bundle extras = i.getExtras();
if(extras != null)
{
int code = extras.getInt("code");
if(code == 1)
{
ClearReleasesCache(); // just a private method of A
setResult(1, i);
finish();
return;
}
}
// do everything else as usual
setContentView...
}
Now, the problem is this (I’ve noticed it in debugging):
When I launch A from B, I want A to finish, as the code indicates here. When I launch A from another activity that’s not B, I want it to run as usual (and it does). But finish() and return do nothing here – I can see when debugging that after the return call, it jumps back into onCreate, it doesn’t shut down the activity.
That is, onActivityResult() in B is never called.
What’s wrong here?
cant you just switch the if condition?
EDIT: but are you sure the return statement does not worK?