问题描述
我已经创建了一个Android应用程序,它运行正常在所有手机。但在我的阿尔卡特手机是不一样的手机进入到深度睡眠模式和数据网络出现故障使应用程序不会得到一个数据网络,并不会从服务器同步数据。
I have created an android app which runs fine in all phones. But in my Alcatel phone it doesn't as the phone goes to a deep sleep mode and the data network fails so the app doesn't get a data network and doesn't sync the data from the server .
我的设计...
SystemBootReceiver
- > (DataSyncService)服务
- > (MyBroadcastReceiver)的BroadcastReceiver
- > (MyDataService)服务
SystemBootReceiver
--> (DataSyncService)Service
--> (MyBroadcastReceiver)BroadcastReceiver
--> (MyDataService)Service
.
所以这里是系统启动时我启动 DataSyncService
在这里我设置了 AlarmManager
(重复),并调用 MyBroadcastRecever
。调用在 BroadcastRecever
我停下 DataSyncService
致电 stopself()
。
So here on system boot I start DataSyncService
where I set up the AlarmManager
(repeated) and call the MyBroadcastRecever
. After calling the BroadcastRecever
I stop DataSyncService
by calling stopself()
.
现在的 MyBroadcastRecever
调用 MyDataService
。
我碰到哪一个与所述prevent手机进入深度睡眠模式WakeLocks。所以,我实现了它在 MyDataService
的onCreate()
方法
I came across WakeLocks which as said prevent the phone from going in deep sleep mode.So I implemented it inside MyDataService
onCreate()
method
PowerManager pm = (PowerManager)
getSystemService(Context.POWER_SERVICE);
mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "My Tag");
mWakeLock.acquire();
和发布()
停止服务之前之后锁定。
And release()
the wake lock before stopping the service.
我还建立在Android清单的权限。
I have also set the permission in android Manifest.
但这并没有工作。因此,对于快速检查我用<一个href="https://play.google.com/store/apps/details?id=eu.thedarken.wl&feature=search_result#?t=W251bGwsMSwxLDEsImV1LnRoZWRhcmtlbi53bCJd"相对=nofollow> WAKE LOCK 从市场上的应用程序。
But this didn't work. So for a quick check I used WAKE LOCK app from the market .
不过这也没睡醒的手机了。我再次跨越WAKE来到我的Android(应用程序从商店中删除)的应用程序,从市场和安装它..这里一个神奇的事情发生了。
But this also didn't wake the phone up. Again I came across WAKE MY ANDROID (app removed from store) app from market and installed it .. and a magic happened here.
它不停地在电话活着。
由于在此应用程序的描述说,他们还使用了一个唤醒锁定
。所以我缺少什么呢?
As the description in this app says that they have also used a Wake Lock
. So what am I missing then ?
是否有一个执行错误或设计问题?
Is there an implementation mistake or a design issue ?
推荐答案
你有你的服务锁定从不运行 - 使你的服务是永远不会运行
The lock you have in your service never runs - cause your service is never run
嗯 - 你必须使用一个 WakefulIntentService - 让你的 MyDataService
延长 WakefulIntentService
,并在您接收呼叫 WakefulIntentService.doWakefulWork(背景下,MyDataService.class)
Well - you have to use a WakefulIntentService - make your MyDataService
extend WakefulIntentService
and in your receiver call WakefulIntentService.doWakefulWork(context, MyDataService.class)
或实现静态锁双方你的服务和接收器共享 - 这将是非常棘手
Or implement a static lock shared by both your service and receiver - which would be tricky.
如果使用无线网络,你也应该需要使用 WifiLock
- 在的你清醒的意图服务 - 可能很麻烦
If using wifi you should also need to use a WifiLock
- inside your wakeful intent service - can get tricky
这篇关于Android的深度睡眠和唤醒锁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!