OnActivityResult cannot call due to orientation change

I have two actions named

"First" and "Second"

when I call the startActivityForResult() method in the first action, it will go into the second activity and take some data and come back.

If the orientation of the second action has changed, then after receiving the data, it does not call onActivityResult() .

It calls the create function.

What should I do so that the data taken from the second action is saved, and the onActivityResult() method is onActivityResult() , even if I change the orientation.

+4
source share
2 answers

In the application manifest, did you remember that your First activity was the parent of your Second action? Something like that:

 <activity android:name=".Second" android:parentActivityName=".First"> <meta-data android:name="android.support.PARENT_ACTIVITY" android:value=".First"/> </activity> 

Because if you do, then onActivityResult() should be called in First , even if the screen orientation was different when you called finish() in Second .

0
source

When the orientation changes, the application restarts, which means that it restarts.

You can block the orientation change in AndroidManifest.xml by adding this line to the Activity declaration:

 android:orientation="portrait" 

or if you want landscape orientation:

 android:orientation="landscape" 
-4
source

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


All Articles