Completion / Intention

I make this program move to another activity in order to get some data, and then return the data using intent to my main activity. The code that I have at the moment opens a new action, it receives and sends data, but it seems to "restart" my main activity when the "End" () function is called.

Question: How to stop my second process by restarting my main activity?

Primary 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 
+4
source share
3 answers

The way this should work. You need to override the onActivityResult method of your main action to get the stringPath from the intent.

+3
source

Ok It seems you are missing this line in the definition of onActivityResult.

super.onActivityResult (requestCode, resultCode, data);

0
source

It seems that your activity is being recreated again. Try overriding onSaveInstanceState and use savedInstanceState on onCreate . It should work.

0
source

Source: https://habr.com/ru/post/1369346/


All Articles