A. B. C |. |. | MainActivity Bluetooth Routines with CallBack
MainActivity Serves 2 purposes for me:
- Manages Bluetooth BLE system calls, including a “CallBack” function that the system calls when a scan is started with: bleScanner.startScan(filters, scanSettings, scanCallback)
- Serves as “traffic cop” or “controller” for which activity the user sees, either A, B, or C.
A, B, C is always started from MainActivity with something like:
startActivityForResult <Act A> (1)
A, B, C always finishes with something like:
setResult(9996, intent) finish()
And A, B, C iare never resident at the same Time.
So, suppose A is active, and a TextView is filled with data obtained in CallBack and needs to be refreshed whenever new data comes in. All good moving in and out of A, B, C UNTIL a CallBack occurs. The system immediately jumps to the CallBack method in MainActivity with No normal lifecycle calls (onPause, onExit, etc..) and A is left on the stack.
I would like to have a way to kill A from MainActivity after the CallBack and start over clean. I have tried various things such as:
((Activity) Class.forName(className).newInstance()).finish();
Trying to get top with:
val am = this.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
val taskInfo = am.getRunningTasks(1)
val componentInfo = taskInfo[0].topActivity
val Actvity_Name = taskInfo[0].topActivity?.className
val PKG_Name = componentInfo?.packageName
And then tried killing Activity_Name with various techniques unsuccfully.
I would appreciate help with this issue.