Use finishAffinity instead of finishAndRemoveTask

The method used to finish (`finishAndRemoveTask`) an activity prior to going back to `MainActivity` or restarting the process led to the process prematurely exiting entirely and would result in it not being restarted or another activity not being launched. This has now been fixed by utilizing `finishAffinity` in its place which correctly only ends the activities with the same affinity as the caller.
This commit is contained in:
PixelyIon 2021-10-29 21:20:04 +05:30
parent 9f5ab13858
commit 9e3b7a75b2

View File

@ -55,7 +55,7 @@ class EmulationActivity : AppCompatActivity(), SurfaceHolder.Callback, View.OnTo
private var shouldFinish : Boolean = true private var shouldFinish : Boolean = true
/** /**
* If the activity should return to [MainActivity] or just call [finishAndRemoveTask] * If the activity should return to [MainActivity] or just call [finishAffinity]
*/ */
var returnToMain : Boolean = false var returnToMain : Boolean = false
@ -183,7 +183,7 @@ class EmulationActivity : AppCompatActivity(), SurfaceHolder.Callback, View.OnTo
shouldFinish = false shouldFinish = false
if (returnToMain) if (returnToMain)
startActivity(Intent(applicationContext, MainActivity::class.java).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)) startActivity(Intent(applicationContext, MainActivity::class.java).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
finishAndRemoveTask() finishAffinity()
} }
} }
} }
@ -199,7 +199,7 @@ class EmulationActivity : AppCompatActivity(), SurfaceHolder.Callback, View.OnTo
emulationThread!!.join(250) emulationThread!!.join(250)
if (emulationThread!!.isAlive) { if (emulationThread!!.isAlive) {
finishAndRemoveTask() finishAffinity()
startActivity(intent) startActivity(intent)
Runtime.getRuntime().exit(0) Runtime.getRuntime().exit(0)
} }