mirror of
https://github.com/kvorschk/Magisk.git
synced 2026-12-04 19:10:47 -05:00
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
This commit is contained in:
@@ -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()
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user