9

Android请求打开蓝牙导致应用很卡顿的问题

 2 years ago
source link: https://blog.csdn.net/ljphhj/article/details/124739407
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Android请求打开蓝牙导致应用很卡顿的问题

相信有些朋友会使用这种方式来调用系统的弹窗来打开蓝牙,但是今天我在项目中发现这样的话,会导致我们的App卡顿,Service也被全部杀死了

设备:三星,S20+,Android 10

val intent = Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE)
activity.startActivityForResult(intent,  REQUEST_CODE_ENABLE_BT)

参考了下Stack Overflow上的

startActivityForResult doesn’t work with singleInstance. Is your activity configured as single instance ? (android:launchMode=“singleInstance”)

但是我发现我当前的activity也并非是singleInstance也不是singleTask,去掉了for result,直接startActivity没有问题。


val intent = Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE)
activity.startActivity(intent)

暂时记录下,等后面项目时间充裕再去进行跟踪分析。(有清楚的网友也可以留言给我说一下)


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK