Java – when the direction changes, the activity will continue to restart

How can I prevent the activity from restarting when the screen rotates or the user slides the keyboard on the phone? Is that possible? Do you have a job? All relevant answers were appreciated

Solution

You can use the A specific attribute is declared in the activity element in XML to perform this operation The problematic element is called Android: configchanges. You need to register the string value of the direction

<activity android:name=".MyActivity"
      android:configChanges="orientation"
      android:label="@string/app_name">

From @ L_ 419_ 1@:

Doing so will cause the activity not to restart and will also call back onconfigurationchanged() so that you can handle the changes yourself

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
分享
二维码
< <上一篇
下一篇>>