🏆本文收录于《CSDN问答解答》专栏,主要记录项目实战过程中的Bug之前因后果及提供真实有效的解决方案,希望能够助你一臂之力,帮你早日登顶实现财富自由🚀;同时,欢迎大家关注&&收藏&&订阅!持续更新中,up!up!up!!
问题描述
android 蓝牙闪退:android APP在蓝牙模拟键盘扫描条码设备开机时闪退.
日志如下:
D/CrashReport: >>> com.hainatong.qiping.MainActivity onPaused <<<
I/CrashReport-Native: Set native info: isAppForeground(false)
E/onPause: (MainActivity.java:79)onPause
E/MainActivity: (MainActivity.java:85)onStop
I/[LiveEventBus]: observer removed: com.jeremyliao.liveeventbus.core.LiveEventBusCore$ObserverWrapper@df354b3
I/[LiveEventBus]: observer removed: com.jeremyliao.liveeventbus.core.LiveEventBusCore$ObserverWrapper@f8f8d0c
E/onDestroy: (BaseActivity.java:308)viewModel==com.hainatong.qiping.vm.LoginVM@f4f1976
D/CrashReport: >>> com.hainatong.qiping.MainActivity onDestroyed <<<
W/ainatong.qipin: Accessing hidden field Landroid/view/inputmethod/InputMethodManager;->mCurRootView:Landroid/view/View; (greylist, reflection, allowed)
W/ainatong.qipin: Accessing hidden field Landroid/view/inputmethod/InputMethodManager;->mServedView:Landroid/view/View; (greylist-max-p, reflection, denied)
W/ainatong.qipin: Accessing hidden field Landroid/view/inputmethod/InputMethodManager;->mNextServedView:Landroid/view/View; (greylist-max-p, reflection, denied)
E/BaseTitleActivity: (BaseTitleActivity.java:66)onDestroy
W/TextToSpeech: stop failed: not bound to TTS engine
W/TextToSpeech: shutdown failed: not bound to TTS engine
D/Surface: Surface::disconnect(this=0x7d012f5000,api=1)
D/View: [Warning] assignParent to null: this = DecorView@ecc6732[MainActivity]
D/com.base.common: JPush BaseAppMainActivity
D/CrashReport: >>> com.hainatong.qiping.MainActivity onCreated <<<
I/[LiveEventBus]: observe observer: com.jeremyliao.liveeventbus.core.LiveEventBusCore$ObserverWrapper@a0b84b2(com.base.common.view.base.BaseViewUtils$1@d01ec03) on owner: com.hainatong.qiping.MainActivity@7e82449 with key: user_update_success
E/MainActivity: (MainActivity.java:150)initView
D/CrashReport: >>> com.hainatong.qiping.MainActivity onResumed <<<
I/CrashReport-Native: Set native info: isAppForeground(true)
V/PhoneWindow: DecorView setVisiblity: visibility = 4, Parent = null, this = DecorView@caa8099[]
D/ViewRootImpl[MainActivity]: hardware acceleration = true , fakeHwAccelerated = false, sRendererDisabled = false, forceHwAccelerated = false, sSystemRendererDisabled = false
V/PhoneWindow: DecorView setVisiblity: visibility = 0, Parent = android.view.ViewRootImpl@cb6700c, this = DecorView@caa8099[MainActivity]
D/CrashReport: >>> com.hainatong.qiping.MainActivity onPaused <<<
I/CrashReport-Native: Set native info: isAppForeground(false)
E/onPause: (MainActivity.java:79)onPause
D/View: [ANR Warning]onMeasure time too long, this =android.widget.LinearLayout{719b100 V.E...... ......ID 0,0-0,0}time =578 ms
D/View: [ANR Warning]onMeasure time too long, this =androidx.appcompat.widget.ContentFrameLayout{fde8d39 V.E...... ......ID 0,0-0,0 #1020002 android:id/content}time =579 ms
D/View: [ANR Warning]onMeasure time too long, this =androidx.appcompat.widget.FitWindowsLinearLayout{3dfaf7e V.E...... ......ID 0,0-0,0 #7f090050 app:id/action_bar_root}time =579 ms
D/View: [ANR Warning]onMeasure time too long, this =android.widget.FrameLayout{72a4cdf V.E...... ......ID 0,0-0,0}time =580 ms
D/View: [ANR Warning]onMeasure time too long, this =android.widget.LinearLayout{3e8dd2c V.E...... ......ID 0,0-0,0}time =580 ms
D/View: [ANR Warning]onMeasure time too long, this =DecorView@caa8099[MainActivity]time =581 ms
I/GED: ged_boost_gpu_freq, level 100, eOrigin 2, final_idx 15, oppidx_max 15, oppidx_min 0
E/MainActivity: (MainActivity.java:85)onStop
V/PhoneWindow: DecorView setVisiblity: visibility = 4, Parent = android.view.ViewRootImpl@cb6700c, this = DecorView@caa8099[MainActivity]
I/[LiveEventBus]: observer removed: com.jeremyliao.liveeventbus.core.LiveEventBusCore$ObserverWrapper@8161eae
I/[LiveEventBus]: observer removed: com.jeremyliao.liveeventbus.core.LiveEventBusCore$ObserverWrapper@a0b84b2
E/onDestroy: (BaseActivity.java:308)viewModel==com.hainatong.qiping.vm.LoginVM@f4f1976
D/CrashReport: >>> com.hainatong.qiping.MainActivity onDestroyed <<<
W/ainatong.qipin: Accessing hidden field Landroid/view/inputmethod/InputMethodManager;->mServedView:Landroid/view/View; (greylist-max-p, reflection, denied)
W/ainatong.qipin: Accessing hidden field Landroid/view/inputmethod/InputMethodManager;->mNextServedView:Landroid/view/View; (greylist-max-p, reflection, denied)
E/BaseTitleActivity: (BaseTitleActivity.java:66)onDestroy
W/TextToSpeech: stop failed: not bound to TTS engine
W/TextToSpeech: shutdown failed: not bound to TTS engine
D/View: [Warning] assignParent to null: this = DecorView@caa8099[MainActivity]
I/Choreographer: Skipped 35 frames! The application may be doing too much work on its main thread.
如上问题有来自我自身项目开发,有的收集网站,有的来自读者,如有侵权,立马删除。
解决方案
如下是上述问题的解决方案,仅供参考:
从你提供的日志来看,Android APP在蓝牙模拟键盘扫描条码设备开机时发生闪退,可能的原因有:
- ANR(Application Not Responding):
日志中有多条ANR警告,如:
[ANR Warning]onMeasure time too long
这表明onMeasure
方法执行时间过长,导致应用无法及时响应。这通常是由于复杂的布局或不合理的视图嵌套造成的。需要优化布局以减少测量时间。
- 硬编码问题:
日志显示:
W/ainatong.qipin: Accessing hidden field Landroid/view/inputmethod/InputMethodManager;->mCurRootView:Landroid/view/View; (greylist, reflection, allowed)
这是对Android灰名单API的访问,建议检查代码,避免使用反射访问这些API。
- 资源未正确释放:
日志中的TextToSpeech
提示:
W/TextToSpeech: stop failed: not bound to TTS engine
W/TextToSpeech: shutdown failed: not bound to TTS engine
这表明可能存在TextToSpeech资源未正确释放的情况。确保在onDestroy
或onPause
中释放TextToSpeech实例。
- ViewModel未正确配置:
日志中的onDestroy
方法调用显示:
E/onDestroy: (BaseActivity.java:308)viewModel==com.hainatong.qiping.vm.LoginVM@f4f1976
这可能意味着ViewModel的生命周期没有管理好,需要检查ViewModel的实现和使用方式。
- 主线程工作量过大:
日志中的Choreographer
提示:
I/Choreographer: Skipped 35 frames! The application may be doing too much work on its main thread.
这表明主线程可能执行了太多工作,导致帧跳过。需要检查是否有耗时的操作在主线程运行,并将其移到后台线程。
- 初始化视图错误:
日志中的initView
方法调用显示错误:
E/MainActivity: (MainActivity.java:150)initView
这表明在初始化视图时出现了问题。需要检查initView
方法的实现,找出具体的错误原因。
- 日志中还提到了LiveEventBus:
I/[LiveEventBus]: observer removed
这表明LiveEventBus的观察者被移除。检查LiveEventBus的使用,确保事件的注册和反注册正确。
解决这些问题通常需要对代码进行详细的审查和调试。你可以使用Android Studio的Logcat功能来获取更详细的错误信息,并使用debug模式运行应用来逐步跟踪问题。此外,确保应用遵守Android开发的最佳实践,包括合理管理资源、避免在主线程执行耗时操作、正确使用ViewModel和LiveData等。
希望如上措施及解决方案能够帮到有需要的你。
PS:如若遇到采纳如下方案还是未解决的同学,希望不要抱怨&&急躁,毕竟影响因素众多,我写出来也是希望能够尽最大努力帮助到同类似问题的小伙伴,即把你未解决或者产生新Bug黏贴在评论区,我们大家一起来努力,一起帮你看看,可以不咯。
若有对当前Bug有与如下提供的方法不一致,有个不情之请,希望你能把你的新思路或新方法分享到评论区,一起学习,目的就是帮助更多所需要的同学,正所谓「赠人玫瑰,手留余香」。
☀️写在最后
ok,以上就是我这期的Bug修复内容啦,如果还想查找更多解决方案,你可以看看我专门收集Bug及提供解决方案的专栏《CSDN问答解惑-专业版》,都是实战中碰到的Bug,希望对你有所帮助。到此,咱们下期拜拜。
码字不易,如果这篇文章对你有所帮助,帮忙给 bug菌 来个一键三连(关注、点赞、收藏) ,您的支持就是我坚持写作分享知识点传播技术的最大动力。
同时也推荐大家关注我的硬核公众号:「猿圈奇妙屋」 ;以第一手学习bug菌的首发干货,不仅能学习更多技术硬货,还可白嫖最新BAT大厂面试真题、4000G Pdf技术书籍、万份简历/PPT模板、技术文章Markdown文档等海量资料,你想要的我都有!
📣关于我
我是bug菌,CSDN | 掘金 | InfoQ | 51CTO | 华为云 | 阿里云 | 腾讯云 等社区博客专家,C站博客之星Top30,华为云2023年度十佳博主,掘金多年度人气作者Top40,掘金等各大社区平台签约作者,51CTO年度博主Top12,掘金/InfoQ/51CTO等社区优质创作者;全网粉丝合计 30w+;硬核微信公众号「猿圈奇妙屋」,欢迎你的加入!免费白嫖最新BAT互联网公司面试真题、4000G PDF电子书籍、简历模板等海量资料,你想要的我都有,关键是你不来拿哇。