[英]Android app crashes in the API26 emulator - runs ok in API25 and 27
I have been updating my app and have been testing it in Android Studio emulators from API25 to API33.我一直在更新我的应用程序,并在 Android Studio 模拟器中从 API25 到 API33 对其进行了测试。 When I try to run it in an API26 emulator (Android 8.0) the app crashes immediately on launch, with the message "AboutMyJourney has stopped" (The app is called AboutMyJourney)当我尝试在 API26 模拟器 (Android 8.0) 中运行它时,应用程序在启动时立即崩溃,并显示消息“AboutMyJourney 已停止”(该应用程序称为 AboutMyJourney)
I have put a Logcat message at the beginning of the Main (launch) activity:我在主要(启动)活动的开头放置了一条 Logcat 消息:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.v("sTag","Starting MainActivity");
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
setContentView(R.layout.activity_main);
......more stuff
and one at the beginning of the activity that gets called next:一个在接下来被调用的活动开始时:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.v("sTag","Starting AgreeTermsActivity");
...more stuff
but it crashes without ever displaying the messages in the Logcat screen.但它在没有在 Logcat 屏幕中显示消息的情况下崩溃了。
I wondered if it could be something to do with the permissions in the Manifest, but I can't figure out what there might be that affects just API26.我想知道这是否与清单中的权限有关,但我无法弄清楚可能仅影响 API26 的内容。 The permissions are:权限是:
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <!-- uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" / -->
<uses-permission
android:name="android.permission.WAKE_LOCK"
tools:node="replace" />
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_DOWNLOAD_MANAGER" />
<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" />
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM"/>
However, the app runs without any problem in the API25 and API27 emulators, and the Logcat messages get displayed ok.但是,该应用程序在 API25 和 API27 模拟器中运行没有任何问题,并且 Logcat 消息显示正常。
I have tried deleting and re-installing the SDK platform for API26 and then deleting and re-creating the emulator, but it doesn't solve the problem.我已经尝试删除并重新安装 API26 的 SDK 平台,然后删除并重新创建模拟器,但它并没有解决问题。 The device definition I am using for all the emulators is Nexus 5X.我为所有模拟器使用的设备定义是 Nexus 5X。
One more bit of info: The Event Log shows that the Gradle build was completed and the launch succeeded - no messages after that.还有一点信息:事件日志显示 Gradle 构建已完成并且启动成功 - 之后没有消息。
Can anyone suggest any reasons why I'm getting this problem in API26 and not with other API versions?谁能提出我在 API26 而不是其他 API 版本中遇到此问题的任何原因? Why are the Log messages not showing even though they are right at the start of onCreate?为什么日志消息没有显示,即使它们就在 onCreate 的开始?
(NOTE: I have included the code snippets just to show that the Log messages are at the start of onCreate. The code then goes on to call many other methods, and it just isn't feasible to include all the code here) (注意:我包含代码片段只是为了表明日志消息位于 onCreate 的开头。代码然后继续调用许多其他方法,并且在此处包含所有代码是不可行的)
Thanks for the advice about using the stack trace (I'm still very much a learner!)感谢您提供有关使用堆栈跟踪的建议(我仍然是一个学习者!)
The key piece of information in the stack trace was: ComponentInfo{com.barney.aboutmyjourney/com.barney.aboutmyjourney.MainActivity}: java.lang.IllegalStateException: Only fullscreen opaque activities can request orientation
堆栈跟踪中的关键信息是: ComponentInfo{com.barney.aboutmyjourney/com.barney.aboutmyjourney.MainActivity}: java.lang.IllegalStateException: Only fullscreen opaque activities can request orientation
I removed this: android:screenOrientation="portrait"
from the main (launch) activity in the manifest, and it works.我从清单的主要(启动)活动中删除了这个: android:screenOrientation="portrait"
,并且它有效。 To make sure that the main activity uses portrait orientation, I have put some java code in the activity instead.为了确保主要活动使用纵向,我在活动中放置了一些 java 代码。
I don't know why it was failing only with API26, but all is now OK, anyway.我不知道为什么它只在 API26 上失败,但现在一切正常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.