ACTION_REQUEST_ENABLE intent的startActivityForResult()大约需要6秒

时间:2012-11-12 17:43:52

标签: android android-activity bluetooth

我需要显示“你想打开蓝牙吗?”我的Android应用程序中的对话框。

为此,我刚刚从official android documentation获得了代码。

从我的活动OnCreate()方法我执行以下操作:

if (!mBluetoothAdapter.isEnabled()) {
    Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
    startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
}

有效。但是对话框出现需要大约6秒钟!

对应的logcat:

01-06 06:53:04.789 I/ActivityManager(  313): START {act=android.bluetooth.adapter.action.REQUEST_ENABLE cmp=com.android.settings/.bluetooth.RequestPermissionActivity u=0} from pid 6512
01-06 06:53:04.812 I/ActivityManager(  313): START {act=com.android.settings.bluetooth.ACTION_INTERNAL_REQUEST_BT_ON cmp=com.android.settings/.bluetooth.RequestPermissionHelperActivity u=0} from pid 907
01-06 06:53:09.843 I/ActivityManager(  313): Displayed com.android.settings/.bluetooth.RequestPermissionActivity: +5s36ms (total +5s114ms)
01-06 06:53:09.843 I/ActivityManager(  313): Displayed com.android.settings/.bluetooth.RequestPermissionHelperActivity: +5s28ms

这种异常缓慢的原因是什么?我该如何调试/修复它?

1 个答案:

答案 0 :(得分:0)

我认为你的问题可能就在这里:

  1. onPause()onStop()onSaveInstanceState()会造成沉重负担。
  2. 您的应用程序使用了大量内存,因此窗口管理器等待垃圾收集器
  3. 您在服务或异步过程中负担过重
  4. 您填写了IPC(进程间通信)内存,但可能这不是您的理由。
  5. 我认为你的问题可能是第一个问题。试着检查并告诉我们你找到了什么。