[英]Automatic change of activity : Landscape and portrait mode in Android
I have two activities in my Android app. 我的Android应用程序中有两项活动。 On click I can move from one activity to another, back and forth. 单击时,我可以从一个活动来回移动。 But when I am changing from landscape to portrait mode and vice versa, my activity is getting changed automatically which I did not expect. 但是,当我从横向模式更改为纵向模式时,反之亦然,我的活动会自动更改,这是我没有想到的。 I expect it to remain on the same activity even if it is changed to portrait or landscape mode. 我希望即使将其更改为纵向或横向模式,它也可以保留在同一活动中。 So what might be the problem? 那么可能是什么问题呢?
Update 更新资料
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.dmacs.myapplication">
<application
android:allowBackup="true"
android:icon="@drawable/icon1"
android:label="@string/app_name"
android:logo="@drawable/icon2"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".second_main">
</activity><!-- ATTENTION: This was auto-generated to add Google Play services to your project for
App Indexing. See https://g.co/AppIndexing/AndroidStudio for more information. -->
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
</application>
</manifest>
<activity
android:name=".MainActivity"
android:screenOrientation="sensor"
android:configChanges="orientation"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
I simply added this line: android:screenOrientation="sensor"
我只是添加了这一行: android:screenOrientation="sensor"
It overrides the system(if your system can lock orientation) 它会覆盖系统(如果您的系统可以锁定方向)
Also add this line: android:configChanges="orientation"
还要添加以下行: android:configChanges="orientation"
It prevents any updates from occuring triggered by the orientation 它可以防止方向触发任何更新
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.