-
-
Save easterapps/7127ce0749cfce2edf083e55b6eecec5 to your computer and use it in GitHub Desktop.
fun triggerRestart(context: Activity) { | |
val intent = Intent(context, MainActivity::class.java) | |
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) | |
context.startActivity(intent) | |
if (context is Activity) { | |
(context as Activity).finish() | |
} | |
Runtime.getRuntime().exit(0) | |
} |
Yes, great work. This would also reload the Application class - so it is an app restarter.
Also I use it as an extension function fun Activity.triggerRestart
Is it possible if the User exists the App that it will automatically restart?
Is it possible if the User exists the App that it will automatically restart?
@danielehrhardt I think it should work, but haven't tested it yet
You could at least cite your sources...
https://github.com/JakeWharton/ProcessPhoenix/blob/trunk/process-phoenix/src/main/java/com/jakewharton/processphoenix/ProcessPhoenix.java
which was featured here on SO https://stackoverflow.com/a/22345538/12871582
Sorry i didn't understand how put the code in a project. I must put in a different class? I must put a Receive, Service? Thank you so much!
Awesome, this satisfies The app called finish() on an activity very recently.
Also,
Runtime.getRuntime().exit(0)
can be replaced with kotlin.system.exitProcess(0)
Finally! It helped me to delete database and recreate with default data. Thanks.
I can't get it work, sorry
package com.mycompany.myapp.util
import android.app.Activity
import android.content.Intent
import com.mycompany.myapp.ui.MainActivity
fun triggerRestart(context: Activity) {
val intent = Intent(context, MainActivity::class.java).apply {
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
}
context.startActivity(intent)
context.finish()
kotlin.system.exitProcess(0)
}
@russellhoff how about to replace kotlin.system.exitProcess(0)
with Runtime.getRuntime().exit(0)
?
already tried but with no success
already tried but with no success
Try to explain what is not working. It works on Andoid SDK 31, called from the main thread.
@easterapps thank you very much it works like a charm on all devices ❤️
awesome, help me solve memory leak of DexClassLoader
Works like a charm for Andriod 10