- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在使用通用软件 WakefulIntentService
进行唤醒工作。与使用 commonsware library 相比有什么优势吗?而不是 WakefulBroadcastReceiver
来自支持库?
这是我使用支持库的代码
import android.support.v4.content.WakefulBroadcastReceiver;
public class SimpleWakefulReceiver extends WakefulBroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// This is the Intent to deliver to our service.
Intent service = new Intent(context, SimpleWakefulService.class);
// Start the service, keeping the device awake while it is launching.
Log.i("SimpleWakefulReceiver", "Starting service @ " + SystemClock.elapsedRealtime());
startWakefulService(context, service);
}
}
public class SimpleWakefulService extends IntentService {
public SimpleWakefulService() {
super("SimpleWakefulService");
}
@Override
protected void onHandleIntent(Intent intent) {
Log.i("SimpleWakefulReceiver", "Completed service @ " + SystemClock.elapsedRealtime());
SimpleWakefulReceiver.completeWakefulIntent(intent);
}
}
This是文档。
最佳答案
它们几乎是一样的。
支持库的 WakefulBroadcastReceiver
采用部分唤醒锁,将锁 ID 作为额外内容放入您应该提供给 IntentService< 的
完成处理后,您必须在其中调用 Intent
中completeWakefulIntent ()
。所以获取和释放是在不同的地方完成的,这有点代码味道。
CommonsWare 的 WakefulIntentService
自己获取和释放部分唤醒锁。
如果您同意获取和释放应该在同一个地方完成,您可以将常规 BroadcastReceiver
与 WakefulIntentService
结合使用。
如果您不太介意并认为使用知名库更重要,这样新开发人员(或一年后的您)就不必(重新)学习新东西,那么请使用支持库。
更新
此外:在 WakefulBroadcastReceiver
的文档中,它警告可能会被中断并丢失唤醒锁。您需要在 IntentService
中获取自己的唤醒锁以防止出现这种情况。使用 CommonsWare,您可以只依靠它来重新获取锁。
关于android - 支持库中的 WakefulBroadcastReceiver 与 commonsware 的 cwac-wakeful,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27763793/
本文整理了Java中com.commonsware.cwac.security.ZipUtils类的一些代码示例,展示了ZipUtils类的具体用法。这些代码示例主要来源于Github/Stackov
在 commonsware 书籍教程 #6 中,我严格按照说明进行操作。我创建了包含 zip 下载中\library 目录内容的并行目录。我确保 empublite 项目处于合规级别 1.6。我将 A
最初,我有自己的 Adapter 扩展了 BaseAdapter,它工作正常。然后,我尝试通过以下代码采用commonsware EndlessAdapter: public class MyEndl
我正在尝试实现 Commonsware CWAC-Camera,但遇到了将其整合到现有 fragment 中的问题。 我遇到无法使用 .add 或 .replace 的问题,它要我将 CameraFr
应用构建失败并显示以下错误消息 com.intellij.openapi.externalSystem.model.ExternalSystemException: Could not find an
我在我的 android 项目中使用合并列表,直到现在我只是将源代码与我的其余代码一起推送到我的 src 根目录中。但是我没有修改任何东西,所以我认为是时候将这些东西作为库包含进来了。我克隆了第一个
关闭。这个问题需要details or clarity .它目前不接受答案。 想改进这个问题吗? 通过 editing this post 添加细节并澄清问题. 关闭 9 年前。 Improve t
本文整理了Java中com.commonsware.cwac.security.ZipUtils.unzip()方法的一些代码示例,展示了ZipUtils.unzip()的具体用法。这些代码示例主要来
在我的应用程序中,我有 CommosWare 的 WakefulIntentservice。从 doWakefulWork 方法中,我调用了几个自己编写的方法。例如: @Override protec
创建一个包含以下内容的 Activity 1)编辑文本(Commonsware RichEditText) 2) 带有以下按钮的工具栏 粗体、斜体、下划线、删除线、字体、居中对齐、左对齐、右对齐、两端
我在我的应用程序中添加了 tedpicker https://github.com/ParkSangGwon/TedPicker 但是现在几个星期以来,当我尝试将 gradle 与互联网同步时,这个错
我正在使用通用软件 WakefulIntentService 进行唤醒工作。与使用 commonsware library 相比有什么优势吗?而不是 WakefulBroadcastReceiver来
我正在将 CWAC StreamProvider 集成到我的代码中,但在运行我的代码后,我在 logcat 中看到无法获取提供程序 com.commonsware.cwac.provider.Stre
我正在按照自己的方式完成 CommonsWare master book 的 4.7 版。我正在学习教程 #12。我的问题与 ModelFragment 中的 deliverModel() 方法有关。
我是一名优秀的程序员,十分优秀!