当用户从通知菜单更改系统主题时,我的活动会重新创建并再次加载数据,这不是我的应用程序的要求。
有没有可能防止系统主题更改以这种方式影响我的应用程序?
在清单文件中尝试下面的代码
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity"
android:configChanges="uiMode"> //★★★★add this line★★★★
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Sources: https://proandroiddev.com/daynight-applying-dark-mode-without-recreating-your-app-c8a62d51092d
android:configChanges
,并且您尝试的特定配置更改在android:configChanges
列表中时,才会调用onConfigurationChanged()
。小米可能正在执行与标准Android不同的操作。 - CommonsWare