我应该使用安卓程序=":远程"在我的接收器? [英] Should I use android: process =":remote" in my receiver?

查看:95
本文介绍了我应该使用安卓程序=":远程"在我的接收器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个被称为每隔一段时间BroadcastReceiver的,而且我注意到很多人用

I have a BroadcastReceiver which is called every so often, and I have noticed many people use

android: process =":remote" 

在他们的接收器。矿是用来检查的几件事情,如果条件匹配,则触发报警。我的问题是我应该用我已经在我的清单上面贴行了?如果是的话这样做有什么好处?

in their receiver. Mine is used to check a few things and if the conditions match then activate an alarm. My question is should I use the line I had posted above in my manifest? And if so what are the benefits of doing so?

推荐答案

通过与安卓定义你的接收器:程序=:远程你基本上运行接收机在不同的进程(= VM)。对于典型的使用情况,您不需要在不同的进程运行它,不管你想要做也许可以运行得很好本地(在您的APK程序)。

By defining your receiver with android:process=":remote" you basically run your receiver in a different process (= VM). For typical use-cases, you don't need to run this in a different process, and whatever you want to do can probably run just fine locally (in your APK process).

使用机器人的缺点:工艺=:远程的是,你需要额外的资源,它运行(在这种情况下,一个单独的进程)。这样做时,你基本上有2个虚拟机打交道,有的模式,如单身,静态字段不能再被你的应用程序和远程服务之间共享。

The drawback of using android:process=":remote" is that you need additional resources for it to run (in this case a separate process). When doing so, you're basically dealing with 2 VMs, and some patterns like singletons, static fields can no longer be shared between your app and your remote service.

使用机器人的好处:程序=:远程是对一些用例,它可能是很方便的启动,将让上运行的服务(在自己的进程),你关机后您的应用程序,或者如果你想远程客户端能够绑定到你的服务。在调用的onReceive()方法在单独的进程中运行时,你的广播接收器不会阻止你的应用程序的主线程(但是,也有实现这一点其他方式)。

The benefit of using android:process=":remote" is that for some use-cases, it might be handy to start a service that will keep on running (in its own process) after you've shutdown your application, or if you want remote clients to be able to bind to your service. Your broadcast receiver will not block your applications main thread when running in a separate process upon calling the onReceive() method (however, there are other ways of implementing this).

我发现,大部分的时间,对于最常见的用例,你可以逃脱不使用机器人:工艺=远程

I've found that most of the time, for most common use-cases, you can get away without using android:process="remote".

这篇关于我应该使用安卓程序=":远程"在我的接收器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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