Android前台服务在一些天后停止请求位置更新。

huangapple go评论129阅读模式
英文:

Android foreground service stops Requesting updates for locations after some days

问题

我有一个无限的前台服务,每10秒请求位置更新,同时将这些位置和其他信息发送到数据库。我成功地在应用程序在后台运行或手机待机时更新位置。该应用程序在某些天内正常运行,但出于我无法理解的原因,位置在手机仍在运行且服务仍在发送其他信息的情况下停止了。

手机会停止请求位置但仍然运行前台服务的原因是什么呢?

该服务被设置为黏性服务,因此如果内存不足,它应该重新启动,并且在服务启动时触发位置更新请求。

我的应用程序已经开启了“始终允许”位置设置,就像我所说的,正常运行了2到3天。

我曾考虑过电池充电不足以运行位置请求的问题,但迄今为止没有找到相关信息。

我还尝试过使用唤醒锁来保持应用程序更新位置,但没有奏效。

英文:

I have an endless foreground service that request locations updates every 10 sec, in parallel, it sends this locations and others informations to a database.
I managed to update the location while the app is in the background or when the phone is on standby.
The app works fine for some days but for some reason that I cannot understand, the locations somehow stops while the phone is still running and the service still sends the other informations.

Is there a reason why the phone would stop request locations but still run the foreground service ?

The service is set as a Sticky service so it should restart if the memory runs out of space and the request update locations is triggered when the service is started.

The "Allow all the time" location setting is on for my app and like I said works fine for 2 to 3 days.

I was thinking about a problem concerning the battery charge not being sufficient to run location request, but didn't found anything on the subject so far.

I also tried a Wakelock to keep the app updating locations but didn't work.

答案1

得分: 1

以下是翻译好的部分:

"For others still looking for answers. I faced the same problem. The answer is actually on the documentation.

You have to set the foregroundServiceType as stated on the documentation.

          android:name=".MyMediaPlaybackService"
          android:foregroundServiceType="mediaPlayback"
          android:exported="false">
      </service>

Find more information on the link below:

https://developer.android.com/about/versions/14/changes/fgs-types-required"

英文:

For others still looking for answers. I faced the same problem. The answer is actually on the documentation.

You have to set the foregroundServiceType as stated on the documentation.

&lt;service
          android:name=&quot;.MyMediaPlaybackService&quot;
          android:foregroundServiceType=&quot;mediaPlayback&quot;
          android:exported=&quot;false&quot;&gt;
      &lt;/service&gt;

Find more information on the link below:

https://developer.android.com/about/versions/14/changes/fgs-types-required

huangapple
  • 本文由 发表于 2023年3月10日 01:04:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/75687806.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定