Извлечение переменной из inner класса

Являясь новичком в программировании на Kotlin, возник вопрос: как я могу достать переменную mConnectionState из класса IncomingHandler и воспользоваться ею в методе onStartCommand? message приходит из activity.

class BoundService : Service() {

    var mMessenger: Messenger = Messenger(IncomingHandler())
    lateinit var mConnectionState:ConnectionState

    enum class ConnectionState(i: Int) {
        CONNECTED(1),
        DISCONNECTED(1),
    }

    override fun onBind(intent: Intent): IBinder? {
        Toast.makeText(applicationContext, "Service Binding...", Toast.LENGTH_LONG).show()
        return mMessenger.binder
    }

    open inner class IncomingHandler(): Handler() {
        override fun handleMessage(msg: Message) {
            when (msg.what) {
                ConnectionState.DISCONNECTED.ordinal-> mConnectionState = ConnectionState.DISCONNECTED
                ConnectionState.CONNECTED.ordinal -> mConnectionState = ConnectionState.CONNECTED
            }
            super.handleMessage(msg)
            Log.d("State", "$mConnectionState")
        }
    }

    override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
        val notificationIntent = Intent()
        val pendingIntent: PendingIntent = PendingIntent.getActivity(this,0, notificationIntent, 0)
        val notification = NotificationCompat.Builder(this, channelID)
            .setContentTitle("Example Service")
            .setSmallIcon(
                when (mConnectionState) {
                    ConnectionState.DISCONNECTED->R.drawable.ic_thumb_down_black_24dp
                    ConnectionState.CONNECTED->R.drawable.ic_thumb_up_black_24dp
                }
            )
            .setContentText("Example")
            .setContentIntent(pendingIntent)

        val notificationManager: NotificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
        notificationManager.notify(startId,notification.build())

        startForeground(startId, notification.build())
        return START_NOT_STICKY

    }
}

Ответы (0 шт):