如何减少应用的电池使用量?

时间:2017-10-05 04:22:46

标签: xamarin.ios xamarin.forms xamarin.android battery-saver

我正在开发一款应用程序,每10-20秒跟踪一次用户位置。为了使其在后台和移动锁定阶段工作,我不得不进行以下代码编辑:

在Android中:

我添加了" Wake_Lock"的许可。并在MainActivity.cs中添加了一行代码,如

this.Window.SetFlags(WindowManagerFlags.KeepScreenOn, WindowManagerFlags.KeepScreenOn);

在iOS(AppDelegate.cs)中:

UIApplication.SharedApplication.IdleTimerDisabled = true;

这使得功能很好,并且即使在后台也会跟踪每10秒的位置,并且移动设备被锁定,这是好的。但是通过添加此代码,应用程序的电池使用量会大幅增加。

如果我做错了什么,有人可以帮助我,并建议我解决电池使用问题。

1 个答案:

答案 0 :(得分:0)

而不是使用“UIApplication.SharedApplication.IdleTimerDisabled = true;”为防止手机进入睡眠模式,您可以尝试使用“背景位置”吗?

您可以查看this演示应用

相关问题