I have been updating my app and have been testing it in Android Studio emulators from API25 to 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)
I have put a Logcat message at the beginning of the Main (launch) activity:
@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.
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. 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.
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. The device definition I am using for all the emulators is 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.
Can anyone suggest any reasons why I'm getting this problem in API26 and not with other API versions? Why are the Log messages not showing even though they are right at the start of 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)
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 orientationI removed this:
android:screenOrientation="portrait"from the main (launch) activity in the manifest, and it works. To make sure that the main activity uses portrait orientation, I have put some java code in the activity instead.I don't know why it was failing only with API26, but all is now OK, anyway.