0

I am new to Kotlin development. below is an attempt to create an intentservice. i followed some tutorials on the internet but at run time i received the below mentioned error in the logcat. please let me know how can i fix this error

MainActivity:

public val LOG_TAG : String = "MainActivity";
public val BackgroundIntentServiceAction = "android.intent.action.CUSTOME_ACTION_1"

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)

    val btnStartService = findViewById<Button>(R.id.btnStartService)
    btnStartService.setOnClickListener{startService()}
}

private fun startService() {
    val intent = Intent(this@MainActivity, BackgrounIntentService::class.java).apply {
        intent.setAction(BackgroundIntentServiceAction)
    }
    startService(intent);
}

intentservice:

class BackgrounIntentService : IntentService("BackgroundIntentService") {

private val LOG_TAG = "BackgroundIntentService"


override fun onCreate() {
    super.onCreate()
    Log.d(LOG_TAG, "onCreate")
}

override fun onHandleIntent(intent: Intent?) {
    TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
    Log.d(LOG_TAG, "onHandleIntent")

}

}

manifest

class BackgrounIntentService : IntentService("BackgroundIntentService") {

private val LOG_TAG = "BackgroundIntentService"


override fun onCreate() {
    super.onCreate()
    Log.d(LOG_TAG, "onCreate")
}

override fun onHandleIntent(intent: Intent?) {
    TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
    Log.d(LOG_TAG, "onHandleIntent")

}

}

logcat error

2019-07-04 18:55:07.521 7642-7642/com.example.kotlin_v1 D/BackgroundIntentService: onCreate

--------- beginning of crash
2019-07-04 18:55:07.528 7642-7675/com.example.kotlin_v1 E/AndroidRuntime: FATAL EXCEPTION: IntentService[BackgroundIntentService]
Process: com.example.kotlin_v1, PID: 7642
kotlin.NotImplementedError: An operation is not implemented: not implemented
    at com.example.kotlin_v1.BackgrounIntentService.onHandleIntent(BackgrounIntentService.kt:18)
    at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:76)
    at android.os.Handler.dispatchMessage(Handler.java:105)
    at android.os.Looper.loop(Looper.java:164)
    at android.os.HandlerThread.run(HandlerThread.java:65)
2019-07-04 18:55:07.704 7642-7660/com.example.kotlin_v1 D/EGL_emulation: eglMakeCurrent: 0x99d05060: ver 3 1 (tinfo 0x99d03140)
2019-07-04 18:55:07.710 7642-7660/com.example.kotlin_v1 D/OpenGLRenderer: endAllActiveAnimators on 0x97858e80 (RippleDrawable) with handle 0x99d03ad0
Amr Bakri
  • 11
  • 1
  • 3
  • 1
    In `onHandleIntent` you left the auto-generated `TODO("not implemented")`. The `TODO` function throws an error and that's what is crashing your app. – gpunto Jul 04 '19 at 17:09

1 Answers1

4

That error comes from:

TODO("not implemented")

Presumably, that came from the Android Studio new-IntentService wizard. The idea is that you replace all TODO code with something else.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491