I have two activities, LoginActivity and MainActivity. When I press a button in my LoginActivity I want to call a function in MainActivity.How can I achieve this?
- MainActivity function*
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)
}
Please give me a proper solution. Thanks
Activitybut there's nothing wrong in the way it is currently used. Because, in this particular case,MainActivityis running or not doesn't matter and it cannot cause a runtime error. This is done to simplify the code and make it easier to understand the code.functionto clear the app data and thefunctionI am running is causing to close my app after clearing app data. that's why I want to restart it back. So I think it is not possible to restart the app with a singleactivity.