Search code examples
androidandroid-widgetremoteview

Getting java.lang.IllegalStateException: Binder has been finalized! from a home screen widget


I have an Android app that has a home screen widget. When I add one with a particular configuration I get an error "AppName has stopped". Logcat reveals the following crash log:

E/System: java.lang.IllegalStateException: Binder has been finalized!
    at android.os.BinderProxy.transactNative(Native Method)
    at android.os.BinderProxy.transact(Binder.java:748)
    at android.security.IKeystoreService$Stub$Proxy.abort(IKeystoreService.java:1373)
    at android.security.KeyStore.abort(KeyStore.java:529)
    at android.security.keystore.AndroidKeyStoreCipherSpiBase.finalize(AndroidKeyStoreCipherSpiBase.java:744)
    at android.security.keystore.AndroidKeyStoreRSACipherSpi$PKCS1Padding.finalize(Unknown Source:0)
    at java.lang.Daemons$FinalizerDaemon.doFinalize(Daemons.java:250)
    at java.lang.Daemons$FinalizerDaemon.runInternal(Daemons.java:237)
    at java.lang.Daemons$Daemon.run(Daemons.java:103)
    at java.lang.Thread.run(Thread.java:764)

I tried to debug that every way I could think of (enabling breakpoints on exceptions, stepping through my code that's executed before the exception, etc.) to no avail. The exception seems to be coming not from my code but from another process that I don't have access to. How do I fix this problem?


Solution

  • After some experimenting I found that the exception happened after this line:

    rv.setInt(R.id.task_item_color_header, "setBackgroundColor", Color.parseColor(color));
    

    Turned out that in some cases color (which is a String) does have a value but it's "null". That causes a crash when trying to set a non-existing color as the background to a RemoteView. However, since RemoteView's values are not set directly but are rather delegated to the OS to set, the crash occurred in another process. So, if you have a similar problem - check the values that you try to set on your RemoteViews