【问题标题】:I want to send my location to the server each 1 minute even the app in the background in android?我想每 1 分钟将我的位置发送到服务器,即使是 android 后台的应用程序?
【发布时间】:2020-11-11 23:18:03
【问题描述】:

即使是后台的应用程序(android),每 1 分钟调用一次方法的最佳做法是什么, 我正在使用 Handler(Looper.getMainLooper()) 在前台执行此操作,但我需要在后台调用方法,甚至是应用程序

private fun runScheduleMethods() {
    mainHandler.post(object : Runnable {
        override fun run() {
            viewModel.loadCurrentLocation(locationRequest)
            mainHandler.postDelayed(this, 1000 * 60)
        }
    })
}

【问题讨论】:

    标签: android kotlin background-task


    【解决方案1】:

    使用带有通知的前台服务(因为如果通知处于活动状态,那么 android OS 将不会杀死它)

    这里是博客 祝你好运..!

    https://medium.com/@ramkumarv3/foreground-service-with-notification-channel-ac6697c8a6d1

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-12-11
      • 2012-05-23
      • 1970-01-01
      • 2014-02-26
      • 1970-01-01
      • 2023-04-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多