简体   繁体   English

android:进程和进程名称

[英]android:process and process name

I'm trying to understand the android:process attribute. 我正在尝试理解android:process属性。 Ref says : 参考说

If the name assigned to this attribute begins with a colon (':'), a new process, private to the application, is created when it's needed. 如果分配给此属性的名称以冒号(':')开头,则在需要时会创建一个专用于应用程序的新进程。 If the process name begins with a lowercase character, a global process of that name is created. 如果进程名称以小写字符开头,则会创建该名称的全局进程。 A global process can be shared with other applications, reducing resource usage. 可以与其他应用程序共享全局进程,从而减少资源使用。

Will a process be created if the name doesn't begin with a colon? 如果名称不以冒号开头,是否会创建进程? What if it begins with a capital letter? 如果它以大写字母开头怎么办? And what happens if I mix the two rules? 如果我混合这两个规则会发生什么?

I need to have two components from two packages run in the same process to save resources (and to avoid having two "running apps" listed in the apps manager). 我需要在同一进程中运行两个包中的两个组件以节​​省资源(并避免在应用程序管理器中列出两个“正在运行的应用程序”)。 What should be my process name? 我的流程名称应该是什么? Do I need a global process? 我需要全球流程吗?

EDIT: 编辑:

I tried with a simple lower case name (first package's name) and it seems it's working like I want. 我尝试了一个简单的小写名称(第一个包的名称),似乎它的工作就像我想要的那样。 Still I think I don't get the rules. 我仍然认为我没有得到规则。

And what happens if I mix the two rules? 如果我混合这两个规则会发生什么?

That's not possible. 那是不可能的。 A colon is not a capital letter. 冒号不是大写字母。

I need to have two components from two packages run in the same process to save resources (and to avoid having two "running apps" listed in the apps manager). 我需要在同一进程中运行两个包中的两个组件以节​​省资源(并避免在应用程序管理器中列出两个“正在运行的应用程序”)。

That's really not a good idea. 这真的不是一个好主意。 Put them in the same package, or have them run independently. 将它们放在同一个包中,或让它们独立运行。

Not only would you have to mess around with android:process , but you also have to mess around with android:sharedUserId . 你不仅要乱用android:process ,还要乱用android:sharedUserId Neither of these are meant to be used by ordinary SDK developers, particularly android:sharedUserId . 这些都不是普通SDK开发人员使用的,特别是android:sharedUserId In fact, if you have already distributed your application, you can't use android:sharedUserId unless you're willing to break all your existing users' apps, since you will no longer be able to access your original data, since it'll be owned by some other user account. 事实上,如果你已经分发了你的应用程序,你就不能使用android:sharedUserId除非你愿意打破所有现有用户的应用程序,因为你将无法再访问原始数据,因为它会由其他一些用户帐户拥有。

Furthermore, unless you have evidence to the contrary, I would not assume that this will somehow "avoid having two 'running apps' listed in the apps manager". 此外,除非您有相反的证据,否则我不会认为这会以某种方式“避免在应用管理器中列出两个'正在运行的应用'”。

Now, I am all for efficiency, and so creating extra processes for grins (eg, misguided advice to make "remote services" run in custom processes) is a bad idea. 现在,我全力以赴提高效率,因此为grins创建额外的流程(例如,误导性建议使“远程服务”在自定义流程中运行)是一个坏主意。 And if you work for a device manufacturer or a firm with 20+ Android developers or something, and you want to mess around with this, you're going to need to find places where it is used in the AOSP and reverse-engineer the information you seek, since this stuff is seriously under-documented. 如果您为一家设备制造商或拥有20多名Android开发人员的公司工作,并且您想要解决这个问题,那么您将需要找到在AOSP中使用它的位置并对信息进行反向工程你寻求,因为这些东西严重缺乏记录。 And even there, I am not seeing it used between multiple packages, except for android.process.acore and com.android.phone , which are seriously low-level processes and are not going to be typical of non-firmware apps. 即使在那里,我也没有看到它在多个软件包之间使用,除了android.process.acorecom.android.phone ,它们是严重的低级进程,并不是典型的非固件应用程序。

Hence, I really recommend that you leave these things alone. 因此,我真的建议你单独留下这些东西。

i guess you are speaking about background services, right? 我想你是在谈论后台服务,对吗? If you start your service without the ":", the service is running the same process as your application does, in that case it's called a "local service". 如果您在没有“:”的情况下启动服务,则该服务正在运行与您的应用程序相同的过程,在这种情况下,它称为“本地服务”。 If you start it with the ":" it will run in its own process, called "remote service". 如果用“:”启动它,它将在自己的进程中运行,称为“远程服务”。 In that case can be used maybe by other activities. 在这种情况下,可以使用其他活动。

By default, Android creates a process for an application when the first of its components needs to run. 默认情况下,Android在第一个组件需要运行时为应用程序创建一个进程。 All components then run in that process. 然后所有组件都在该过程中运行。 The name of the default process matches the package name set by the element. 默认进程的名称与元素设置的包名称匹配。

Seems you don't have to provide the android:process parameter, except you want to specify the name of your application process. 似乎您不必提供android:process参数,除非您要指定应用程序进程的名称。 And if you want some component of your application run inside a different process, as I described with the service example above. 如果您希望应用程序的某些组件在不同的进程中运行,正如我在上面的服务示例中所描述的那样。

hope that helps little bit. 希望有点帮助。 nyyrikki nyyrikki

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM