-1

This is the handler which is I want to run always except the phone switch off

 val handler = Handler()

            val runnable: Runnable = object : Runnable {
                override fun run() {
                    val geoPoint = GeoPoint(lat!!.toDouble(), lon!!.toDouble())

                    val liveUser = LiveUser(auth.uid.toString(), geoPoint, Timestamp.now())

                    updateLiveLocation(liveUser)

                    handler.postDelayed(this, 2000)
                }
            }
            //Start
            handler.postDelayed(runnable, 5000)
ADM
  • 20,406
  • 11
  • 52
  • 83

1 Answers1

0

You can use WorkManager. Also if you want to get location from background you should consider and aware of background limitations.

Handler will be closed after entry point destroyed that is why you have to deal with background services.

https://developer.android.com/about/versions/oreo/background-location-limits

Gökberk Yağcı
  • 376
  • 1
  • 4
  • 10