如何使用CPU在深度休眠模式下执行任何操作 [英] How to use CPU to perform any operation in Deep Sleep mode

查看:645
本文介绍了如何使用CPU在深度休眠模式下执行任何操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在机器人新。我和我的应用程序大约3周左右挣扎。我需要发送并接收在正常模式和睡眠模式包。 我的应用必须交换数据的5秒。我试着用 alarmmanager ,但在Android上5这不是作品。在机器人 5的时间间隔改变它60秒。这样的解决方案,使电池很快磨损。当我使用正常的AsyncTask,而不是 IntentService ,那么它的工作原理,只有当屏幕 ON 应用可见。当应用程序被隐藏或我点击功率关闭然后交换数据停止工作。什么是最好的解决方案?

I'm new in android. I struggle with my application approximately 3 weeks. I need sent and receive packets in normal mode and sleep mode. My app must exchange data a 5 seconds. I tried using alarmmanager but on android 5 it's not works. On android 5 an interval changes it on 60 seconds. Such a solution makes the battery wears out quickly. When I use normal asynctask, not IntentService, then it works only when screen is ON and app is visible. When app is hidden or I click power OFF then exchange data stops working. What is the best solutions?

推荐答案

即使RTC_WAKEUP不利于大部分的时间。

Even RTC_WAKEUP doesn't help most of the times.

解决方案,对于我的应用程序工作时,设备在深度睡眠模式:结果
使用<一个href=\"http://developer.android.com/reference/android/support/v4/content/WakefulBroadcastReceiver.html\"相对=nofollow> WakefulBroadcastReceiver ,提供AlarmManager相结合。看看这个<一个href=\"http://porcupineprogrammer.blogspot.se/2014/02/when-do-you-absolutely-need.htmlhttp://porcupineprogrammer.blogspot.se/2014/02/when-do-you-absolutely-need.html?m=1\"相对=nofollow>教程关于这个问题。

Solution that worked for my app when device in deep sleep mode:
Use WakefulBroadcastReceiver combined with AlarmManager. Take a look at this tutorial on this subject.

服务由startWakefulService启动()和完成时,它通过调用completeWakefulIntent(意向)释放之后锁。因此,该设备将被允许回去睡觉。

Service is started by startWakefulService() and when it is finished, it releases the wake lock by calling completeWakefulIntent(intent). So the device will be allowed to go back to sleep.

我不加入任何code。搜索如何与AlarmManager使用WakefulBroadcastReceiver例子。即使WakefulBroadcastReceiver文档有一些模板code。

I'm not adding any code. Search for examples on how to use WakefulBroadcastReceiver with AlarmManager. Even WakefulBroadcastReceiver doc has some template code.

同时也减少报警的频率,这样就可以避免耗尽这么大的电池​​。

Also reduce the frequency of alarm so you can avoid draining so much battery.

这篇关于如何使用CPU在深度休眠模式下执行任何操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆