adroitandroid / Near

A P2P library for Android for discovery on local networks using UDP and transfer in general using TCP sockets
https://goo.gl/kioAiQ
MIT License
349 stars 92 forks source link

Crashes app after going to background #14

Closed anpez closed 3 years ago

anpez commented 4 years ago

OnPause of my activity I do:

    if (nearDiscovery.isDiscovering) {
      nearDiscovery.stopDiscovery()
    }
    if (nearDiscovery.isDiscoverable) {
      nearDiscovery.makeNonDiscoverable()
    }
    if (nearConnect.isReceiving) {
      nearConnect.stopReceiving(false)
    }

but still it crashes with this error:

java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter intent         at com.adroitandroid.near.connect.server.TcpServerService.onStartCommand(TcpServerService.kt)
AndroFlo commented 4 years ago

Hi, @ANPez the intent parameter of the onStartCommand in TcpServerService class is null but set as no nullable. You can make it non nullable because the documentation say

This may be null if the service is being restarted after its process has gone away, and it had previously returned anything except START_STICKY_COMPATIBILITY.

anpez commented 4 years ago

That's right, the TcpServerService is crashing when the system restarts the service. I think we should make it nullable to handle that case