1.切换白天黑夜问题
切换白天黑夜是否会把Activity重新销毁创建,有两种情况
(1)正常情况下如果应用没有特殊配置,切换白天黑夜当前activity会走正常销毁创建流程。
(2)可以在manifest加上这个属性configChanges:"uiMode"
增加后切换白天黑夜模式不会重新销毁创建Activity,但是其实切换在当前Activity并没有发生。如果仍然需要再切换时执行相关逻辑,可以重写OnConfigurationChanged方法。
2.切换系统语言回调
通过广播监听系统语言变化:
1.静态注册:
<receiver
android:name="com.XXX.LOCALEReceiver"
android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.LOCALE_CHANGED" />
</intent-filter>
</receiver>
public class XXX extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {undefined
if (intent.getAction().equals(Intent.ACTION_LOCALE_CHANGED)) {
//something to do
}
}
}
2.动态注册
IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_LOCALE_CHANGED);
mContext.registerReceiver(mReceiver, filter);
privateBroadcastReceiver mReceiver = new BroadcastReceiver(){
@Override
publicvoid onReceive(Context context, Intent intent) {
Log.v(TAG, "onReceive intent.getAction():
"+intent.getAction());
if(intent.getAction().equals(Intent.ACTION_LOCALE_CHANGED)) {
//something to do
}
}
};