【发布时间】:2014-06-17 15:19:40
【问题描述】:
假设我想交替运行唤醒和非唤醒服务。
类似于切换按钮的东西。如果它打开,那么我必须使用doWakefulWork() 方法启动我的WakefulIntentService。
如果它关闭,那么我必须在同一个WakefulIntentService 中执行所有相同的任务,但使用不同的方法,在睡眠模式下不与 CPU 和 wifi 交互,就像我所说的非唤醒工作..
我刚刚在我的服务中添加了一个新方法,但无法继续。
public class NetworkCommunicationService extends WakefulIntentService{
private static String UserID;
public NetworkCommunicationService() {
super("NetworkCommunicationService");
}
@Override
protected void doWakefulWork(Intent intent) {
if (Utils.isNetworkAvailable(this))
new SyncValidater().execute();
}
/**I have to do something like this.... */
protected void doNonWakefulWork() {
if (Utils.isNetworkAvailable(this))
new SyncValidater().execute();
}
他们有什么解决方案吗?或者我必须创建一个新服务来完成非清醒工作。
请帮忙。谢谢
【问题讨论】:
标签: android service commonsware-cwac