android - android : battery being drained in background 中的 react-native 应用程序

标签 android react-native

我有一个用 React-Native 构建的应用程序,它在后台运行时会耗尽 Android 设备上的大量电池电量。需要显着减少应用程序的电池使用量。

该应用使用 react-native-background-geolocation (mauron85) 跟踪位置,但仅每 20 分钟(10 快速间隔)获取一次位置更新。

电池使用报告屏幕(大部分时间在后台):

enter image description here

可能是一些依赖或错误的版本?

我的 package.json:

{
  "name": "AwesomeApp",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "react-native start",
    "test": "jest"
  },
  "dependencies": {
    "base-64": "^0.1.0",
    "d3-interpolate": "^1.1.5",
    "es6-promise": "^4.1.1",
    "firebase": "^4.6.0",
    "lodash": "^4.17.4",
    "lodash.range": "^3.2.0",
    "moment": "^2.19.2",
    "numeral": "^2.0.6",
    "react": "16.0.0-alpha.12",
    "react-native": "^0.48.2",
    "react-native-android-location-services-dialog-box": "^2.3.2",
    "react-native-checkbox": "^2.0.0",
    "react-native-drawer": "^2.5.0",
    "react-native-fbsdk": "^0.6.3",
    "react-native-fcm": "^10.0.3",
    "react-native-firebase": "^3.2.0",
    "react-native-google-places": "^2.4.2",
    "react-native-google-signin": "^0.12.0",
    "react-native-keyboard-aware-scroll-view": "^0.4.1",
    "react-native-mauron85-background-geolocation": "^0.5.0-alpha.1",
    "react-native-navbar": "^2.0.1",
    "react-native-permissions": "^1.0.1",
    "react-native-popup-dialog": "^0.9.38",
    "react-native-push-notification": "^3.0.1",
    "react-native-router-flux": "^4.0.0-beta.25",
    "react-native-spinkit": "^1.1.1",
    "react-native-splash-screen": "^3.0.1",
    "react-native-svg": "^5.4.1",
    "react-native-tab-view": "0.0.70",
    "react-redux": "^5.0.6",
    "redux": "^3.7.2",
    "redux-persist": "^5.2.2",
    "redux-thunk": "^2.2.0"
  },
  "devDependencies": {
    "babel-eslint": "^8.0.2",
    "babel-jest": "21.2.0",
    "babel-preset-react-native": "4.0.0",
    "eslint-config-rallycoding": "^3.2.0",
    "jest": "21.2.1",
    "react-test-renderer": "16.0.0-alpha.12"
  },
  "jest": {
    "preset": "react-native"
  },
  "rnpm": {
    "assets": [
      "./assets/fonts/"
    ]
  }
}

背景地理定位的配置:

BackgroundGeolocation.configure({
    desiredAccuracy: 10,
    stationaryRadius: 50,
    distanceFilter: 50,
    startForeground: false,
    debug: false,
    startOnBoot: true,
    stopOnTerminate: false,
    locationProvider: BackgroundGeolocation.ACTIVITY_PROVIDER,
    interval: 1200000, //default 1200000 = 20 minutes
    fastestInterval: 600000, //DEFAULT 600000 = 10 MINUTES
    activitiesInterval: 1200000,  //default 1200000 = 20 minutes
    stopOnStillActivity: false
});

我感谢任何帮助的尝试:)

最佳答案

这是我的 2 美分。屏幕截图显示 Stay Awake : 7h 26m。这似乎是问题所在。似乎您在某处获取未释放的部分唤醒锁。检查Stuck Partial Wake Locks解决方案。它说,我引用:

A partial wake lock becomes stuck if it is held for a long time while your app is running in the background (no part of your app is visible to the user). This condition drains the device's battery because it prevents the device from entering lower power states.

关于android - android : battery being drained in background 中的 react-native 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49284486/

相关文章:

Android 以编程方式调用电话号码

javascript - 使用 JWT Token、React Native 和 Redux 检索用户信息

android - 通过服务器联系 Android 设备

javascript - OnKeyboard 在 Sencha Touch 中隐藏

ios - 在 TabBarIOS 中使用图像 ~ 低质量,色调破坏图像

reactjs - 如何将 Yup 验证架构与 `react-hook-form` lib 中的 Controller 组件一起使用

android - <Image> url 没有显示为 android React Native

react-native - 我应该如何在 React Native Expo 托管应用程序中导入 AccessibilityInfo?

android - 我的应用程序设置屏幕使用首选项或 sqlite 数据库是什么

android - 我可以添加一个按钮吗?