Bluetooth activation Alert dialog multiplication after screen rotation

I have encountered strange issue. From Activity onStart() I request Bluetooth activation and 120s discoverability via intent:

Intent activateBTIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
startActivityForResult(activateBTIntent, BT_ACTIVATE_INTENT);                                   

I use it no matter if the Bluetooth is already activated or not. Android documentation says that Bluetooth will be activated if it was not, and that works fine. In both cases I get system Alert dialog

在这里输入图像描述

When I rotate the screen I observe flickering. Press on Yes/No removes one dialog, but there is still another one below. Performing screen rotation I can get a pile of Alert dialogs, and have to press Yes/No on each to get rid of them.

Described issue is present only if Bluetooth was not already started when intent was sent, otherwise it works correctly. Tried on different 2.2 phones, and issue is present on all. Looks to me like Android system issue.

Has anybody encountered it also, and maybe have some useful hint how to avoid this?

Thanks and regards.


This is a bug in the Settings app that causes this. The RequestPermissionActivity is duplicating its instance of RequestPermissionHelperActivity on rotations.


I was facing the same problem. After spending lots of time with it, i have found one solution.

You can avoid the duplication of the 'Bluetooth activation Alert dialog' by using FLAG_ACTIVITY_NO_HISTORY flag for activateBTIntent . But setting this flag will make startActivityForResult unusable .

The code -

Intent activateBTIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
activateBTIntent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(activateBTIntent);

Using FLAG_ACTIVITY_NO_HISTORY with activateBTIntent will remove the 'Bluetooth activation Alert dialog' activity from the history stack. Thus in this case, when orientation is changed, the 'Bluetooth activation Alert dialog' activity will be finished and newel created(NOT DUPLICATED):

Reference http://developer.android.com/reference/android/content/Intent.html#FLAG_ACTIVITY_NO_HISTORY


(Your post doesn't nearly have enough info, so I'm assuming here...)

I'm not too sure about the startActivityForResult.

You shouldn't do showDialog() in onCreate() if you use a managed AlertDialog. If the Bluetooth thingy does that, could you try not running the above code from onCreate()?

链接地址: http://www.djcxy.com/p/4574.html

上一篇: 需要设计/模式/结构帮助编写一个Java'世界'

下一篇: 屏幕旋转后蓝牙激活警报对话框倍增