Monday, 9 November 2020

Resources$NotFoundException when launching SplashScreen

My application has a SplashScreen implemented as a separate activity.

I've been getting few crash reports on Google Play Console. Here is the stack trace:

java.lang.RuntimeException: 
  at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:3253)
  at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:3349)
  at android.app.ActivityThread.access$1100 (ActivityThread.java:223)
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1794)
  at android.os.Handler.dispatchMessage (Handler.java:102)
  at android.os.Looper.loop (Looper.java:148)
  at android.app.ActivityThread.main (ActivityThread.java:7223)
  at java.lang.reflect.Method.invoke (Native Method)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1230)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1120)
Caused by: android.content.res.Resources$NotFoundException: 
  at android.content.res.Resources.getValue (Resources.java:2558)
  at androidx.appcompat.widget.ResourceManagerInternal.loadDrawableFromDelegates (ResourceManagerInternal.java:252)
  at androidx.appcompat.widget.ResourceManagerInternal.getDrawable (ResourceManagerInternal.java:139)
  at androidx.appcompat.widget.AppCompatDrawableManager.getDrawable (AppCompatDrawableManager.java:411)
  at androidx.appcompat.widget.TintTypedArray.getDrawableIfKnown (TintTypedArray.java:93)
  at androidx.appcompat.app.AppCompatDelegateImpl.attachToWindow (AppCompatDelegateImpl.java:794)
  at androidx.appcompat.app.AppCompatDelegateImpl.ensureWindow (AppCompatDelegateImpl.java:770)
  at androidx.appcompat.app.AppCompatDelegateImpl.onCreate (AppCompatDelegateImpl.java:498)
  at androidx.appcompat.app.AppCompatActivity.onCreate (AppCompatActivity.java:114)
  at my.application.splashscreen.view.Hilt_SplashActivity.onCreate (Hilt_SplashActivity.java:37)
  at my.application.splashscreen.view.SplashActivity.onCreate (SplashActivity.kt:16)
  at android.app.Activity.performCreate (Activity.java:6877)
  at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1136)
  at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:3206)

Here is how my Activity is implemented inside the application:

AndroidManifest.xml

<activity
        android:name="my.application.splashscreen.view.SplashActivity"
        android:theme="@style/SplashTheme">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

SplashActivity.kt

@AndroidEntryPoint
class SplashActivity : AppCompatActivity() {
    private val splashViewModel: SplashViewModel by viewModels()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        if (splashViewModel.isUserLoggedIn())
            proceedToProfileScreen(this)
        else
            proceedToLoginScreen(this)
    }
}

/res/values/styles.xml -> SplashTheme

<style name="SplashTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
    <item name="colorPrimary">@color/networkPrimary</item>
    <item name="colorPrimaryDark">@color/networkPrimaryDark</item>
    <item name="colorAccent">@color/networkFluorescentBlue</item>
    <item name="android:windowBackground">@drawable/bg_splash_screen</item>
</style>

/res/drawable/bg_splash_screen.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@color/networkPrimary" />
    <item>
        <bitmap
            android:gravity="center"
            android:src="@drawable/logo" />
    </item>
</layer-list>

Everything works fine on a regular basis, however, there are still few crashes on some devices. Perhaps someone could help me out with this.

EDIT: As per Google Crashes and ANRs page - this particular issue seems to affect only Android 6.0 (SDK 23). No other phones Android versions are affected by this.



from Resources$NotFoundException when launching SplashScreen

No comments:

Post a Comment