在 Android 设备 (LGP500) 上启用蓝牙
我在 ADT 插件的帮助下在 Eclipse IDE 中生成了一个新项目。接下来,我在主活动(唯一的活动)的 onCreate
方法中添加了启用蓝牙的意图。我还添加了 BLUETOOTH 和 BLUETOOTH_ADMIN 权限并设置了 android:screenOrientation="landscape"
。
现在,如果我启动我的应用程序,蓝牙请求对话框会多次出现(如果您不断对该对话框说“不”)。我可以想象这是因为活动生命周期和屏幕方向的变化。这对我来说似乎很奇怪,因为我明确地将屏幕方向设置为横向。
然后我添加了 android:configChanges="orientation|keyboardHidden"
。现在我的 onCreate
方法只被调用一次,这是肯定的,因为我看到了我的日志!但对话框出现了两次!同样有趣的是,我总是收到一个 onActivityResult
回调。
您能帮助我了解我的申请/我的理解有什么问题吗?我应该怎么做才能向用户展示一次请求蓝牙对话框?
I've generated a new project inside Eclipse IDE with help of the ADT plugin. Next, I added an intent for enabling Bluetooth in the onCreate
method of my main activity (the only activity). I also added BLUETOOTH and BLUETOOTH_ADMIN permissions and set android:screenOrientation="landscape"
.
Now if I start my application the Bluetooth request dialog comes up many times (if you constantly say 'no' to the dialog). I could imagine that this is because of the activity life cycle and screen orientation changes. It seems strange to me because I explicitly set screen orientation to landscape.
Then I added android:configChanges="orientation|keyboardHidden"
. Now my onCreate
method is called only once, that's for sure, because I see my logs! But the dialog comes up twice! And what is also interesting I always get one onActivityResult
callback.
Could you please help me to understand what is wrong in my application/my understanding? What should I do to present to the user the request Bluetooth dialog only once?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用 Activity 的 onStart() 方法
try to use onStart() method of your activity