Java – a new activity is created when the screen orientation is changed

I am new to Android, but I have made many applications in the past year. Please forgive me

I know that when you run the application on the device and change the screen direction by turning the device, the displayed activity will be completely recreated. I go to the YouTube application (I'm using nexus 7 w / Android 4.2.2) and play some videos, and then flip the screen to change the direction. The video continues to play, and all content is resized accordingly... If the activity is completely recreated, How is this possible?

thank you.

resolvent:

Add Android: configchanges to androidmanifest.xml to avoid re creating activities when the direction changes. I hope your landscape and portrait modes have the same layout

    <activity android:label="Your Activity Name" 
    android:configChanges="keyboardHidden|orientation|screenSize"
      android:name="com.yourpackage">

To add more content, I suggest you check the onpause () and onresume () methods. If you are using fragments, please pay attention to onsaveinstancestate and onretaininstate instead of applying the XML change to "activity is broken by design"

http://developer.android.com/training/basics/activity-lifecycle/index.html

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>