-2

My splash screen works in the emulator but with a physical device it crashes. What could be the matter?

styles.xml

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
</style>

<style name="SplashTheme" parent="AppTheme">
    <item name="android:windowBackground">@drawable/splash_screen</item>
</style>

</resources>

splash.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <item
            android:drawable="@drawable/splash_screen"/>

    <item>
        <bitmap
                android:gravity="center"
                android:src="@mipmap/ic_launcher"/>
    </item>

</layer-list>

The above is all I added for a splash screen which works in the emulator. How can I debug the crash with a physical device (Samsung S8).

AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.koolbusiness">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>

    <application
      android:name=".MainApplication"
      android:label="@string/app_name"
      android:icon="@mipmap/ic_launcher"
      android:allowBackup="false"
      android:theme="@style/AppTheme">
        <activity
                android:name=".MainActivity"
                android:label="@string/app_name"
                android:theme="@style/SplashTheme"
                android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
      <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
    </application>

</manifest>

I was able to produce this stacktrace (without losing my mind searching for USB driver) from the google app console.

37 minutes ago on app version 7
Samsung Galaxy S8 (dreamlte), 4096MB RAM, Android 8.0
Report 1
java.lang.RuntimeException: 

  at android.view.DisplayListCanvas.throwIfCannotDraw (DisplayListCanvas.java:229)

  at android.view.RecordingCanvas.drawBitmap (RecordingCanvas.java:97)

  at android.graphics.drawable.BitmapDrawable.draw (BitmapDrawable.java:529)

  at android.view.View.getDrawableRenderNode (View.java:20627)

  at android.view.View.drawBackground (View.java:20563)

  at android.view.View.draw (View.java:20343)

  at com.android.internal.policy.DecorView.draw (DecorView.java:979)

  at android.view.View.updateDisplayListIfDirty (View.java:19297)

  at android.view.ThreadedRenderer.updateViewTreeDisplayList (ThreadedRenderer.java:686)

  at android.view.ThreadedRenderer.updateRootDisplayList (ThreadedRenderer.java:692)

  at android.view.ThreadedRenderer.draw (ThreadedRenderer.java:800)

  at android.view.ViewRootImpl.draw (ViewRootImpl.java:3447)

  at android.view.ViewRootImpl.performDraw (ViewRootImpl.java:3234)

  at android.view.ViewRootImpl.performTraversals (ViewRootImpl.java:2769)

  at android.view.ViewRootImpl.doTraversal (ViewRootImpl.java:1738)

  at android.view.ViewRootImpl$TraversalRunnable.run (ViewRootImpl.java:7745)

  at android.view.Choreographer$CallbackRecord.run (Choreographer.java:911)

  at android.view.Choreographer.doCallbacks (Choreographer.java:723)

  at android.view.Choreographer.doFrame (Choreographer.java:658)

  at android.view.Choreographer$FrameDisplayEventReceiver.run (Choreographer.java:897)

  at android.os.Handler.handleCallback (Handler.java:789)

  at android.os.Handler.dispatchMessage (Handler.java:98)

  at android.os.Looper.loop (Looper.java:164)

  at android.app.ActivityThread.main (ActivityThread.java:6938)

  at java.lang.reflect.Method.invoke (Native Method)

  at com.android.internal.os.Zygote$MethodAndArgsCaller.run (Zygote.java:327)

  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1374)
Rex Nihilo
  • 604
  • 2
  • 7
  • 16
Niklas Rosencrantz
  • 25,640
  • 75
  • 229
  • 424
  • 1
    Pasting the crashlog/stacktrace didn't seem like an obvious step1 to you? – Shark Mar 20 '18 at 14:16
  • @Shark I don't have information where it is. – Niklas Rosencrantz Mar 20 '18 at 14:17
  • 1
    If you don't have the stacktrace (crashlog) then it could be anything and possibly completely unrelated to the thing you pasted. – Shark Mar 20 '18 at 14:18
  • @Shark If I remove it, it works. If I use it, it crashes. It is obviously this code causing the crash. – Niklas Rosencrantz Mar 20 '18 at 14:18
  • 1
    Past your `Logcat` error code – Ali Mar 20 '18 at 14:19
  • @MohammadAli But I have no `Logcat` with my physical device. With the emulator the code works. It only crashed with the physical device. – Niklas Rosencrantz Mar 20 '18 at 14:20
  • In your java file select this Code **`new Handler().postDelayed(new Runnable() { public void run() { // This method will be executed once the timer is over // Start your app main activity Intent i = new Intent(splashScreen.this, MainActivity.class); startActivity(i); // close this activity finish(); } }, SPLASH_TIME_OUT);`** and Debug the code – Ali Mar 20 '18 at 14:25
  • 1
    @NiklasRosencrantz have you tried to connect your physical device to the computer using USB? If you have developer options enabled in your physical device than you will see those logs in "Logcat" section of Android Studio. – muminers Mar 20 '18 at 14:25
  • @muminers I'm going to try that now but it is very much work for something that might be a very simple problem. I just try and add a splash screen. – Niklas Rosencrantz Mar 20 '18 at 14:26
  • @NiklasRosencrantz I can assure you - it's very simple. Just turn on developer options (USB Debbuging) and connect to the PC. Without logcat we are just unable to help. – muminers Mar 20 '18 at 14:28
  • @muminers Now I have two problems. (1) The splash screen. (2) The debugging environment. – Niklas Rosencrantz Mar 20 '18 at 14:32
  • 3
    @NiklasRosencrantz sorry to say but if turning on debugging on your device is to difficult for you than I just wish you luck. What is more not even trying to make debugging easer is just disrespectful to all folks trying to help you. I'm done here... http://www.kingoapp.com/root-tutorials/how-to-enable-usb-debugging-mode-on-android.htm – muminers Mar 20 '18 at 14:35
  • @muminers I can enable USB debugging. That is not a splash screen. I can enable USB debugging but that changes nothing. I can't even get Logcat started with a physical device. There is no "usb_driver" and nobody understands if "Android SDK" means download something else than Android Studio. – Niklas Rosencrantz Mar 20 '18 at 14:46

1 Answers1

1

I used the same method in my app for creating a splashscreen and that worked for me, try these changes and let me know.

styles.xml - remove the parent="AppTheme" part so it should look like this

<style name="SplashTheme">
<item name="android:windowBackground">@drawable/splash_screen</item>
</style>

splash.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

   // use a color here instead like the line below
  <item android:drawable="@color/white"/>

  <item>
    <bitmap
            android:gravity="center"
            android:src="@mipmap/ic_launcher"/>
  </item>

</layer-list>

manifest - use "@style/SplashTheme" as the application theme and remove the android:theme="@style/SplashTheme" line from the main activity.

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.koolbusiness">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>

<application
  android:name=".MainApplication"
  android:label="@string/app_name"
  android:icon="@mipmap/ic_launcher"
  android:allowBackup="false"
  android:theme="@style/SplashTheme">
    <activity
            android:name=".MainActivity"
            android:label="@string/app_name"

  android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
  <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" 
  />
 </application>

</manifest>
Jude Fernandes
  • 7,437
  • 11
  • 53
  • 90