【问题标题】:Android 10 Vivo funtouch Os killed my foreground service on swipe?Android 10 Vivo funtouch Os 在滑动时杀死了我的前台服务?
【发布时间】:2023-01-27 13:49:44
【问题描述】:

我正在开发我开始计数很长一段时间的应用程序,为此我有 startforeground 服务该服务在所有设备上都运行良好,除了像 android 10 vivo funtouch Os 这样的少数设备。其中,当您滑动通知时,它会终止前台服务,因此要解决此问题,只有少数设备会出现这种情况,谢谢

   class MyCountdownService : Service(){


@RequiresApi(Build.VERSION_CODES.O)
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {

  

    Log.i("Boot","intent is ${intent?.action}")

    showNotification()

    wakeLock =
        (getSystemService(Context.POWER_SERVICE) as PowerManager).run {
            newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "EndlessService::lock").apply {
                acquire()
            }
        }

    println("intent ${intent }")
    isServiceStarted =true

  if(intent!=null) {
      val action = intent?.action


      when(action){

          MyCountdownService.ADD_SERVICE ->{
              val countdown = intent.getParcelableExtra<CountDown>(Add_kEY)
              schedule(countdown !!)

          }

          else ->{

              Log.i("Boot","Service boot ")
              serviceScope.launch(Dispatchers.IO) {
                  smsScheduler.reSchedule()
              }

          }


      }



  }else{





      serviceScope.launch(Dispatchers.IO) {
          smsScheduler.reSchedule()
      }


  }

    return START_STICKY } }

//Manifest file

    <uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
   
    <service android:name=".service.MyService"

        />

【问题讨论】:

    标签: android android-studio


    【解决方案1】:

    请按照步骤在 Android 10 Vivo funtouch Os 设备中启用前台服务。

    设置 < 电池 < 后台功耗管理 < 您的应用程序 < 选择不限制后台电源使用。

    enter link description here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-12-16
      • 1970-01-01
      • 2021-07-02
      • 1970-01-01
      • 2017-06-07
      • 2021-11-16
      • 2012-08-26
      • 1970-01-01
      相关资源
      最近更新 更多