Reputation: 701
I know that to open up the Bluetooth settings programmatically.
I do something like this:
Intent intentOpenBluetoothSettings = new Intent();
intentOpenBluetoothSettings.setAction(android.provider.Settings.ACTION_BLUETOOTH_SETTINGS);
startActivity(intentOpenBluetoothSettings);
But doing so will take me to the Bluetooth settings page in the same view/application.
How should I go about if I want the Bluetooth settings page to open up in another view/window/page, outside the application?.
The reason why I want this to be done is so that the user will not confuse the settings page and my app.
Thanks.
Update
I tried doing intentOpenBluetoothSettings.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
But no luck in getting it to open in another view.
Upvotes: 3
Views: 3697
Reputation: 508
I advice reading up a little on android activity lifecycle and backstack.
Settings is NOT running in your app. But normally everything you start is put on the backstack. So if you go from your app to some other app (settings) android will remember that. Your app there is not destroyed but only set on pause (onPause is called).
If you close settings it will return to your app and delete the entry for settings on backstack. I assume that is not the problem here.
But if you don't close settings and then by some means try to start your app again it is not destroyed but only waked up (no onCreate but only onResume). Android will then check that your app has loaded settings currently and settings will show up again.
If you restart your app with an Intent you control (like from a service) You can:
startMyAppIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
The flag will kill the backstack up to the point where your app is on top of the stack so your app will start no matter if it had started settings before. Backstack is not cleared completely so if your app was started by another app you may be able to return to that when pressing the back button.
Upvotes: 0
Reputation: 20258
There are two ways of requesting for enabling Bluetooth:
intentOpenBluetoothSettings.setAction(android.provider.Settings.ACTION_BLUETOOTH_SETTINGS);
or
intentOpenBluetoothSettings.setAction(BluetoothAdapter.ACTION_REQUEST_ENABLE);
If none of them suit your needs, then you might rethink your idea.
Upvotes: 2