使用机器人的:过程机器人、过程

由网友(男人必须洒脱)分享简介:我有这个AndroidManifest.xml文件:I have this AndroidManifest.xml file:我有这个AndroidManifest.xml文件:

I have this AndroidManifest.xml file:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="1" android:versionName="1.0.0.0721"
android:process="com.lily.process" package="com.lily.test">

    <provider android:authorities="com.lily.test"
      android:name="com.lily.test.provider" 
      android:process="com.lily.process">
    </provider>

安卓过程添加既是明显的标记和标签供应商,我知道,如果它被添加为商标签,供应商可以在com.lily.process的过程中运行。但是,什么是它的使用情况,当写成一个明显的标签? 我已试过,但并非所有的组件可以运行在它确定的过程

"android:process" is added both as manifest tag and provider tag, I know if it is added as a provider tag, the provider can be run in the "com.lily.process" process. But what's the usage of it when written as a manifest tag? I have tried, but not all components could be running in the process it identified.

推荐答案

我会同意,没有多少人会发现Android的:过程是一样的应用程序标签的属性是有用的。然而,我发现这是作为一个属性有用的活动的标签。

I would agree that not many people would find android:process to be useful as an attribute of the application tag. However, I have found it to be useful as an attribute of the activity tag.

Android的目的:工艺的活动是指定的活动应该在具有特定名称的进程来启动。可以使用该名称的选择,要么以隔离在其自己的过程(从启动它的1不同)的活性,或迫使它在与使用相同的名称的其他活动的单个过程同居

The purpose of android:process on an activity is to specify that your activity should be launched in a process having a specific name. The choice of that name may be used either to isolate the activity in its own process (different from the one that launched it), or to force it to cohabit in a single process with other activities that use the same name.

%的开发指南(http://developer.android.com/guide/topics/manifest/activity-element.html):

如果分配给该属性的名称以冒号(':'),一个新的进程,专用的应用程序,在需要时和活动的进程中运行,创建如果进程名以。小写字符,活动将在该名的全局进程中运行,只要它有权限这样做。这使得在不同应用程序的组件共享一个过程,减少资源的使用。

"If the name assigned to this attribute begins with a colon (':'), a new process, private to the application, is created when it's needed and the activity runs in that process. If the process name begins with a lowercase character, the activity will run in a global process of that name, provided that it has permission to do so. This allows components in different applications to share a process, reducing resource usage."

我最近发现这个属性是在解决一个问题,我与启动一个应用程序,在某些情况下,是相当接近,仍然适用于某些设备的16MB堆限制一个帮助活性。启动它的帮助下活性,在这些情况下,推我的应用程序超过限制,导致强制关闭。

I have recently found this attribute to be useful in solving a problem I had with launching a help activity for an app that, under certain circumstances, was fairly close to the 16MB heap limit that still applies to some devices. Launching its help activity was, in those situations, pushing my app over the limit, resulting in a force close.

通过使用安卓过程标签,我可以指定我的帮助活动应该在它自己的一个单独的进程来启动。这个过程有其自身的16MB的堆,并且它不计入中启动它我的主要的应用程序堆。这将永久,彻底$ P $运行的堆空间不足,当有助于推出崩溃pvented我的应用程序。

By using the android:process tag, I was able to specify that my help activity should be launched in a separate process of its own. This process had its own 16MB heap, and it was not counted against the heap of my main app that launched it. This permanently and completely prevented my app from running out of heap space and crashing when help was launched.

如果你的启动程序有包名

If your launching app has the package name

com.mycompany.mymainapp

因此​​被认为是一个过程名相同的字符串,那么,如果你使用

and is therefore assigned a process name that is that same string, then, if you use

android:process=":myhelp"

上的启动的活动,将被分配的进程名

on your launched activity, it will be assigned the process name

com.mycompany.mymainapp:myhelp

和这个过程会有自己的,独立的进程ID,您可以查看(例如在DDMS)。

and that process will have its own, separate process ID, which you can view (for example in DDMS).

这至少是我的经验。我测试迄今已在旧摩托的Droid运行CM6(安卓2.2.1),配置有16MB的堆范围内进行的。

That, at least, has been my experience. My testing has so far been performed on an old Moto Droid running CM6 (Android 2.2.1), configured to have a 16MB heap limit.

在我的情况,因为我不希望用户感知的帮助,是独立于我的应用程序,我包括

In my case, since I did not want the user to perceive the help as being separate from my app, I included the

android:excludeFromRecents="true"

属性为prevent出现在最近的应用程序(长preSS主页)列表中的支援活动。我还包括

attribute to prevent the help activity from appearing on the recent apps (long-press Home) list. I also included

android:taskAffinity="com.mycompany.mymainapp.HelpActivity"

其中HelpActivity是帮助活动的名称,来隔离该活动在其自己的任务

where HelpActivity is the name of the help activity, to segregate the activity in its own task

我还补充道:

android:launchMode="singleInstance"

这是用户调用帮助每次被创建到该应用程序的prevent多个实例。

to prevent multiple instances of this app from being created each time the user invoked help.

我还添加了标记:

Intent.FLAG_ACTIVITY_NEW_TASK

要用于启动支援活动的意图。

to the Intent used to launch the help activity.

可能会或可能不需要这些参数,这取决于你正在制作的Andr​​oid的应用:工艺属性

These parameters may or may not be needed, depending upon the use that you are making of the android:process attribute.

考虑多久开发Android设备的时候,有一个技术,可以在某些情况下,让你摆脱你的应用程序成为独立的进程的一部分,会遇到内存限制,每个国家都有它自己的堆,似乎是一个美好的礼物。有可能是在做这个,我还没有考虑或经验丰富的隐患,但到目前为止,一切都很好,在我的特殊情况。

Considering how often one encounters memory limits when developing for Android devices, having a technique that can, in some cases, allow you to break out parts of your app into separate processes, each with its own heap, seems like a wonderful gift. There may be hidden hazards in doing this that I have not yet considered or experienced, but so far, so good, in my particular instance.

阅读全文

相关推荐

最新文章