Reputation: 1552
I am making a that program is going into another activity to get some data, and then returning the data through intent to my main activity. The code I have at the moment does open a new activity, it gets and sends the data but seems to 'restart' my main activity when finish() is called.
Question: How do I stop my second activity restarting my main activity?
Main Activity:
Intent intent = new Intent(AndroidVideoPlayer.this, FileChooser.class);
intent.putExtra("dir", 1);
startActivityForResult(intent, requestCode);
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.d("CheckStartActivity","onActivityResult and resultCode = "+resultCode);
// TODO Auto-generated method stub
myPath = data.getStringExtra("stringPath");
textEmpty.setText(myPath);
myUri = Uri.parse(myPath);
mp = MediaPlayer.create(this, myUri);
}
Secondary Activity:
Intent intent = new Intent(FileChooser.this,AndroidVideoPlayer.class);
intent.putExtra("stringPath",intentPath1);
setResult(1,intent);
finish(); // <--- does close activity, but restarts main activity
Upvotes: 4
Views: 22708
Reputation: 570
It seems like your activity is being recreated again. Try overriding onSaveInstanceState
and using the savedInstanceState
on the onCreate
. It should work.
Upvotes: 0
Reputation: 9375
Ok. You seem to be missing this line inside your onActivityResult definition.
super.onActivityResult(requestCode, resultCode, data);
Upvotes: 0
Reputation: 69228
That's how it is supposed to work. You need to override onActivityResult method of your main activity to get the stringPath from the intent.
Upvotes: 3