I have an application that uses bluetooth and should not be accessible if Bluetooth is disabled on the device.
The way I decided to implement this is as follows:
- created a dispatcher activity that starts when the application first starts.
- this activity checks the status of bluetooth, if bt is off, it sends you on
noBtScreen, if it is on, it puts you onyesBtScreen
the problem is that when the user gets to noBtScreenand then presses the home button, changes the bt status and returns to the application (long press the home button and choosing my application), he comes in noBtScreen, to which he should not get into this moment.
There are, of course, naive ways to fix this, for example, I can check the status of bt in activity onResume, but I think there is a “right” solution that should be used here.
I tried some of the activity parameters in the manifest file in particular, I tried to put the following flags on NoBtTask:
android:finishOnTaskLaunch
android:allowTaskReparentingin combination and not in combination with
android:clearTaskOnLaunch
android:alwaysRetainTaskState
this.finish noBtActivity::onStop, ( , , , , , , , , :
09-21 17: 54: 49.511: INFO/ActivityManager (115): : Intent {cmp = com.test.elad/.NoBtActivity} pid 12603
09-21 17: 54: 49.523: ERROR/Elad (12603): NoBtActivity.onCreate
09-21 17: 54: 49.527: / (12603): NoBtActivity.onStart
09-21 17: 54: 49.527: / (12603): NoBtActivity.onResume
09-21 17: 54: 49.765: INFO/ActivityManager (115): com.test.elad/.NoBtActivity: + 248ms
09-21 17: 54: 51.867: ERROR/Elad (12603): NoBtActivity.onSaveInstanceState
09-21 17: 54: 51.867: ERROR/Elad (12603): NoBtActivity.onPause
09-21 17: 54: 51.867: INFO/ActivityManager (115): : Intent {act = android.intent.action.MAIN cat = [android.intent.category.HOME] flg = 0x10200000 cmp = com. android.launcher/com.android.launcher2.Launcher} pid 115
09-21 17: 54: 51.882: VERBOSE/RenderScript_jni (195): surfaceCreated
09-21 17: 54: 51.882: VERBOSE/RenderScript_jni (195): surfaceChanged
09-21 17: 54: 52.277: / (12603): NoBtActivity.onStop
09-21 17: 54: 56.183: INFO/ActivityManager (115): : Intent {act = android.intent.action.MAIN cat = [android.intent.category.LAUNCHER] flg = 0x10100000 cmp = com. test.elad/.DispatcherActivity} pid 115
09-21 17: 54: 56.265: / (12603): NoBtActivity.onDestroy