可有人请向我解释意图的基本功能在Android OS? [英] Can someone please explain to me the basic function of Intents in the Android OS?

查看:138
本文介绍了可有人请向我解释意图的基本功能在Android OS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来编写应用程序的Andr​​oid操作系统。至于操作系统的通用架构去,据我所知,过程作为Linux进程和每一个沙盒。

I'm new to programming applications for the Android OS. As far as general architecture of the OS goes, I understand that processes are implemented as Linux processes and that each one is sandboxed.

不过,我所用的工控机和系统调用(如果有的话)心乱如麻。我知道的IBinder就是一个形式;包裹都来回发送流程和束之间有包裹的阵列形式(?)。但即使这样,仍然生疏了。同样的,意图。所有的一切,我不明白什么样的IPC的实施以及如何。

However, I'm utterly confused on the IPCs and syscalls (if any) used. I know that the IBinder is a form of this; parcels are sent back and forth between processes and Bundles are array forms of parcels (?). But even that is still unfamiliar to me. Same with Intents. All in all, I don't understand what kinds of IPCs are implemented and how.

可能有人简单给我解释一下使用的是Android OS用户级应用程序与对方和操作系统进行通信的具体方法?我已经做内核编程而在Linux(Ubuntu和Debian)玩各种公益所以它会帮助极大,如果这一切都是关于什么我熟悉...

Could someone briefly explain to me the specific methods used by user level applications in Android OS to communicate with each other and the OS? I've done kernel programming and played with various IPCs in Linux (Ubuntu and Debian) so it would help immensely if this was all explained in relation to what I'm familiar with...

在此先感谢!

推荐答案

Android是一个面向服务的架构的,这意味着一个设备上的所有应用程序由被其它部件使用的高层的消息称为意图的。虽然背后意图跨度的应用场景是使用活页夹发送,这依赖于一个<一个href="http://groups.google.com/group/android-platform/browse_thread/thread/2fa6ba5ef9f81d22/0b91a39d108d02fc"相对=nofollow>共享内存特殊的Andr​​oid味道,我们的目标是为应用程序开发人员是一无所知的执行情况。唯一的要求是,当组件要传递的对象连同其意图由生活在不同过程中的另一个分量以请求的工作,该对象必须 parcelable (想想序列化)。此外,为了让应用程序能够使用其他应用程序的意图,那些意图必须公布在的清单文件使用href="http://developer.android.com/guide/topics/intents/intents-filters.html" rel="nofollow">意图过滤器的

Android is a Service Oriented Architecture which means that all the applications on a device are made up of components that request work be performed by other components using a high level messages called Intents. While behind the scenes Intents that span applications are sent using Binder which relies on a special Android flavor of shared memory, the goal is for applications developers to be blissfully unaware of the implementation. The only requirement is, when a component wants to pass an object along with its "intention" to request work by another component that lives in different process, that object must be parcelable (think serializable). Additionally, in order for applications to use Intents of other applications, those Intents must be published in the manifest file using an Intent Filter.

这是想引发网页的显示将有code,看起来像这样的应用程序:

An application that wanted to trigger the display of a webpage would have code that looks like this:

public class OpenInternet extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        ((Button) findViewById(R.id.OpenInternetButton))
                .setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        Intent i = new Intent(Intent.ACTION_VIEW, Uri
                                .parse("http://www.google.com"));
                        startActivity(i);
                    }
                });
    }
}

这是能够通过显示网页服务的意图将定义以下意图过滤器在其清单所以它会赶上的其他应用程序发送的意图的另一种应用:

Another application that was capable of servicing that Intent by displaying the webpage would define the following intent-filters in its manifest so it would catch the Intent sent by the other application:

        <!-- For these schemes were not particular MIME type has been
             supplied, we are a good candidate. -->
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="http" />
            <data android:scheme="https" />
            <data android:scheme="about" />
            <data android:scheme="javascript" />
        </intent-filter>
        <!--  For these schemes where any of these particular MIME types
              have been supplied, we are a good candidate. -->
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.BROWSABLE" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:scheme="http" />
            <data android:scheme="https" />
            <data android:scheme="inline" />
            <data android:mimeType="text/html"/>
            <data android:mimeType="text/plain"/>
            <data android:mimeType="application/xhtml+xml"/>
            <data android:mimeType="application/vnd.wap.xhtml+xml"/>
        </intent-filter>

除了使用意图,您可以创建使用 AIDL ,允许您执行远程过程调用跨越进程边界。

Beyond using Intents, you can create objects with proxy objects using AIDL that allow you to perform remote procedure calls across the process boundary.

您可能不需要关心,因为你正在运行的内部虚拟机,并​​从中取出几个层次上如何libc中正在执行的系统调用。至于正常IPC的话,你有插座,但你没有System V共享内存的,因为它被认为是有问题的,并删除。

You probably need not be concerned with how libc is performing syscalls since you are running inside a VM and are several levels removed from them. As far as "normal" IPC goes, you have sockets but you don't have System V Shared Memory as it was deemed problematic and removed.

这篇关于可有人请向我解释意图的基本功能在Android OS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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