From 9f512a6a051772a24e1034ddef37d27c945ee3a3 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Sat, 24 Oct 2026 05:56:41 +0000 Subject: [PATCH] app: recreate activity on locale change Without the system's per-app language settings (before Android 13), changing the language in the app relaunched the foreground activity by starting it again and finishing it. MainActivity is singleTask, so the start was delivered to the same instance, which was then finished, and the app closed instead of showing the new language. Recreate the activity instead, and remove relaunch(), which has no other users. Assisted-by: Claude Opus 5.5 --- .../java/com/topjohnwu/magisk/core/base/BaseActivity.kt | 7 ------- .../java/com/topjohnwu/magisk/core/utils/LocaleSetting.kt | 5 +++-- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/app/core/src/main/java/com/topjohnwu/magisk/core/base/BaseActivity.kt b/app/core/src/main/java/com/topjohnwu/magisk/core/base/BaseActivity.kt index 00854a545..e7757dac9 100644 --- a/app/core/src/main/java/com/topjohnwu/magisk/core/base/BaseActivity.kt +++ b/app/core/src/main/java/com/topjohnwu/magisk/core/base/BaseActivity.kt @@ -3,9 +3,7 @@ package com.topjohnwu.magisk.core.base import android.Manifest.permission.POST_NOTIFICATIONS import android.Manifest.permission.REQUEST_INSTALL_PACKAGES import android.Manifest.permission.WRITE_EXTERNAL_STORAGE -import android.app.Activity import android.content.ActivityNotFoundException -import android.content.Intent import android.net.Uri import android.os.Build import android.os.Bundle @@ -125,8 +123,3 @@ class ActivityExtension(private val activity: ComponentActivity) { private const val CONTENT_CALLBACK_KEY = "content_callback" } } - -fun Activity.relaunch() { - startActivity(Intent(intent).setFlags(0)) - finish() -} diff --git a/app/core/src/main/java/com/topjohnwu/magisk/core/utils/LocaleSetting.kt b/app/core/src/main/java/com/topjohnwu/magisk/core/utils/LocaleSetting.kt index 9aaf11d54..8698a9545 100644 --- a/app/core/src/main/java/com/topjohnwu/magisk/core/utils/LocaleSetting.kt +++ b/app/core/src/main/java/com/topjohnwu/magisk/core/utils/LocaleSetting.kt @@ -13,7 +13,6 @@ import androidx.annotation.RequiresApi import com.topjohnwu.magisk.core.AppContext import com.topjohnwu.magisk.core.Config import com.topjohnwu.magisk.core.R -import com.topjohnwu.magisk.core.base.relaunch import org.xmlpull.v1.XmlPullParser import java.util.Locale @@ -47,7 +46,9 @@ interface LocaleSetting { appLocale = localeList?.get(0) LocaleList.setDefault(currentLocaleList) updateResource(AppContext.resources) - AppContext.foregroundActivity?.relaunch() + // Recreate instead of starting a new instance: MainActivity is singleTask, so + // starting it again would deliver the intent to this instance, which is then finished + AppContext.foregroundActivity?.recreate() } @Suppress("DEPRECATION")