Fixed the bug of being unable to restart app
This commit is contained in:
parent
98a78dd717
commit
f707c6984b
1 changed files with 11 additions and 7 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
package cn.super12138.todo.views.settings
|
package cn.super12138.todo.views.settings
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.Process
|
import android.os.Process
|
||||||
|
|
@ -77,11 +78,7 @@ class SettingsActivity : BaseActivity() {
|
||||||
view?.let {
|
view?.let {
|
||||||
Snackbar.make(it, R.string.need_restart_app, Snackbar.LENGTH_LONG)
|
Snackbar.make(it, R.string.need_restart_app, Snackbar.LENGTH_LONG)
|
||||||
.setAction(R.string.restart_app_now) {
|
.setAction(R.string.restart_app_now) {
|
||||||
val intent = Intent(context, MainActivity::class.java).apply {
|
restartApp(context)
|
||||||
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
|
|
||||||
}
|
|
||||||
context.startActivity(intent)
|
|
||||||
exitProcess(0)
|
|
||||||
}
|
}
|
||||||
.show()
|
.show()
|
||||||
}
|
}
|
||||||
|
|
@ -143,8 +140,7 @@ class SettingsActivity : BaseActivity() {
|
||||||
.setTitle(R.string.restore_successful)
|
.setTitle(R.string.restore_successful)
|
||||||
.setMessage(R.string.restore_need_restart_app)
|
.setMessage(R.string.restore_need_restart_app)
|
||||||
.setPositiveButton(R.string.ok) { _, _ ->
|
.setPositiveButton(R.string.ok) { _, _ ->
|
||||||
Process.killProcess(Process.myPid())
|
restartApp(context)
|
||||||
exitProcess(10)
|
|
||||||
}
|
}
|
||||||
.setNegativeButton(R.string.cancel, null)
|
.setNegativeButton(R.string.cancel, null)
|
||||||
.setCancelable(false)
|
.setCancelable(false)
|
||||||
|
|
@ -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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in a new issue