Skip to content

Commit

Permalink
Fixed the bug of being unable to restart app
Browse files Browse the repository at this point in the history
  • Loading branch information
Super12138 committed Feb 21, 2024
1 parent 98a78dd commit f707c69
Showing 1 changed file with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package cn.super12138.todo.views.settings

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.os.Process
Expand Down Expand Up @@ -77,11 +78,7 @@ class SettingsActivity : BaseActivity() {
view?.let {
Snackbar.make(it, R.string.need_restart_app, Snackbar.LENGTH_LONG)
.setAction(R.string.restart_app_now) {
val intent = Intent(context, MainActivity::class.java).apply {
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
}
context.startActivity(intent)
exitProcess(0)
restartApp(context)
}
.show()
}
Expand Down Expand Up @@ -143,8 +140,7 @@ class SettingsActivity : BaseActivity() {
.setTitle(R.string.restore_successful)
.setMessage(R.string.restore_need_restart_app)
.setPositiveButton(R.string.ok) { _, _ ->
Process.killProcess(Process.myPid())
exitProcess(10)
restartApp(context)
}
.setNegativeButton(R.string.cancel, null)
.setCancelable(false)
Expand All @@ -167,5 +163,13 @@ class SettingsActivity : BaseActivity() {
}
}
}

private fun restartApp(restartContext: Context) {
val intent = Intent(restartContext, MainActivity::class.java).apply {
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
}
restartContext.startActivity(intent)
exitProcess(0)
}
}
}

0 comments on commit f707c69

Please sign in to comment.