Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

247
Visualizações
Android service crash when use kotlin language

I am writing an android app with firebase and kotlin. Now I created a kotlin class that extends Service class.

The problem is, after start service if I close the app it crashed!

If I write same code with java all working fine! I can't understand why it crashed when I use kotlin?

Look my code bellow.

myService.kt

class myService : Service() {
    internal var TAG = "tagForLogD"

    override fun onBind(p0: Intent?): IBinder? {
        return null
    }

    override fun onCreate() {
        super.onCreate()
        Log.d(TAG, "myService Created!")
    }

    override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int {
        return Service.START_STICKY
    }

    override fun onDestroy() {
        super.onDestroy()
        Log.d(TAG, "myService destroyed")
    }
}

myService.java

public class myService extends Service {
    String TAG = "tagForLogD";

    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public void onCreate(){
        super.onCreate();
        Log.d(TAG, "myService Created!");
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId){
        return Service.START_STICKY;
    }

    @Override
    public void onDestroy(){
        super.onDestroy();
        Log.d(TAG, "myService destroyed");
    }
}

Thank you for your support.

Logcat throw bellow exception

03-10 15:13:53.847 4911-4911/net.beingup.simplechat E/AndroidRuntime: FATAL EXCEPTION: main
    Process: net.beingup.simplechat, PID: 4911
    java.lang.RuntimeException: Unable to start service net.beingup.simplechat.Notification.myService@11a4382f with null: java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter intent
        at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3975)
        at android.app.ActivityThread.access$2300(ActivityThread.java:218)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1842)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:145)
        at android.app.ActivityThread.main(ActivityThread.java:7007)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
     Caused by: java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter intent
        at net.beingup.simplechat.Notification.myService.onStartCommand(myService.kt)
        at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3958)
over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

You declared intent to be non-null in onStartCommand:

override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int

Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter intent

So instead declare it as Intent?.

Reasons that the passed Intent would be NULL in onStartCommand

over 4 years ago · Santiago Trujillo Relatório

0

If you are using a LifecycleService then this issue was fixed in version 2.2.0-alpha02 of AndroidX Lifecycle library.

You can override:

override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int

(Notice: Intent? instead of Intent)

over 4 years ago · Santiago Trujillo Relatório

0

Google fixed this bug in androidx.lifecycle:lifecycle-service:2.2.0;

code

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda