实现账号冲突和账号更新时弹窗后的 App 重启
This commit is contained in:
parent
cc9783df1d
commit
29b31fbf69
|
|
@ -58,10 +58,10 @@ class MainActivity : AppCompatActivity() {
|
|||
val ctx = instance ?: return@runOnUiThread
|
||||
androidx.appcompat.app.AlertDialog.Builder(ctx)
|
||||
.setTitle("账号冲突")
|
||||
.setMessage("您的 PTT 账号已在其他设备登录,当前设备已被迫下线。\n请点击确认退出并重新登录。")
|
||||
.setMessage("您的 PTT 账号已在其他设备登录,当前设备已被迫下线。\n请点击确认重启应用。")
|
||||
.setCancelable(false)
|
||||
.setPositiveButton("确认") { _, _ ->
|
||||
com.stand.standapp.utils.AppKiller.killApp(ctx)
|
||||
com.stand.standapp.utils.AppKiller.killApp(ctx, restart = true)
|
||||
}
|
||||
.show()
|
||||
}
|
||||
|
|
@ -76,7 +76,7 @@ class MainActivity : AppCompatActivity() {
|
|||
.setMessage("您的 PTT 账号信息已被更新,需要重新登录以应用更改。\n请点击确认重启应用。")
|
||||
.setCancelable(false)
|
||||
.setPositiveButton("确认") { _, _ ->
|
||||
com.stand.standapp.utils.AppKiller.killApp(ctx)
|
||||
com.stand.standapp.utils.AppKiller.killApp(ctx, restart = true)
|
||||
}
|
||||
.show()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,11 +7,11 @@ object AppKiller {
|
|||
|
||||
private var isKilling = false
|
||||
|
||||
fun killApp(context: Context, isCrash: Boolean = false) {
|
||||
fun killApp(context: Context, isCrash: Boolean = false, restart: Boolean = false) {
|
||||
if (isKilling) return
|
||||
isKilling = true
|
||||
|
||||
Timber.tag("AppKiller").i("Starting app cleanup. isCrash: $isCrash")
|
||||
Timber.tag("AppKiller").i("Starting app cleanup. isCrash: $isCrash, restart: $restart")
|
||||
|
||||
try {
|
||||
GpioManager.stopListening()
|
||||
|
|
@ -49,7 +49,21 @@ object AppKiller {
|
|||
LogManager.shutdown()
|
||||
} catch (e: Exception) {}
|
||||
|
||||
if (restart) {
|
||||
try {
|
||||
val intent = context.packageManager.getLaunchIntentForPackage(context.packageName)
|
||||
if (intent != null) {
|
||||
intent.addFlags(android.content.Intent.FLAG_ACTIVITY_NEW_TASK or android.content.Intent.FLAG_ACTIVITY_CLEAR_TASK)
|
||||
val flags = android.app.PendingIntent.FLAG_ONE_SHOT or android.app.PendingIntent.FLAG_IMMUTABLE
|
||||
val pendingIntent = android.app.PendingIntent.getActivity(context, 223344, intent, flags)
|
||||
val mgr = context.getSystemService(Context.ALARM_SERVICE) as android.app.AlarmManager
|
||||
mgr.set(android.app.AlarmManager.RTC, System.currentTimeMillis() + 500, pendingIntent)
|
||||
}
|
||||
} catch (e: Exception) {}
|
||||
}
|
||||
|
||||
android.os.Process.killProcess(android.os.Process.myPid())
|
||||
System.exit(0)
|
||||
}
|
||||
|
||||
fun setupUncaughtExceptionHandler(context: Context) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue