Near icon indicating copy to clipboard operation
Near copied to clipboard

IllegalArgumentException when I exit

Open vankad24 opened this issue 4 years ago • 3 comments

I ran your example and when I exit the app this error appears:

    java.lang.RuntimeException: Unable to start service com.adroitandroid.near.discovery.client.UdpBroadcastService@73c0f23 with null: java.lang.NullPointerException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkNotNullParameter, parameter intent
        at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3449)
        at android.app.ActivityThread.-wrap21(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1633)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6316)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:872)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:762)
     Caused by: java.lang.NullPointerException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkNotNullParameter, parameter intent
        at com.adroitandroid.near.discovery.client.UdpBroadcastService.onStartCommand(UdpBroadcastService.kt)
        at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3432)
        at android.app.ActivityThread.-wrap21(ActivityThread.java) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1633) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:154) 
        at android.app.ActivityThread.main(ActivityThread.java:6316) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:872) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:762) 

This happens on android 7, on android 10 everything is ok. I need some help. Thanks

vankad24 avatar Jan 31 '21 07:01 vankad24

Thank you, @Mikhail57. You helped me solve this problem.

In the file near/discovery/client/UdpBroadcastService.kt you need to add to the method stopSelf()

    ...
    override fun onTaskRemoved(rootIntent: Intent?) {
        stopSelf()
        super.onTaskRemoved(rootIntent)
    }
    ...

vankad24 avatar Feb 04 '21 16:02 vankad24

As Android goes forward, Background Services becomes irrelevant, so you should move to Foreground Services ASAP. Or, as @vankad24 said, you may stop background service when the attached task removed or set the service's flag to stop when the task removed.

Mikhail57 avatar Feb 08 '21 18:02 Mikhail57

As this project is (nearly) dead and hard to maintain because it relies on old android code, I created a new one Klient2Klient test this please instead

I will create an official release tomorrow, in the main time you can get the latest built commit from jitpack

implementaton("com.github.DatL4g.Klient2Klient:Klient2Klient:531f6f3dae")

DatL4g avatar Mar 02 '22 00:03 DatL4g