Android Process Communication: How to pass values between two applications, android process

Source: Internet
Author: User

Android Process Communication: How to pass values between two applications, android process

How do I transfer values between two applications? In fact, this title is too watery. The professional saying is "How do I transfer values between two processes"? What ?! Not professional enough. Okay, you have sex! "Inter-process communication" is actually more professional. This time you are always satisfied! Simply put, it is abbreviated as IPC: Inter-Process Communication.

Guys, if you find this article from search engines or other ways, it means that your Android technology has been upgraded to a very high level ~ Why? No matter which platform, the thread and process are absolutely important and difficult.

The value passing between processes mentioned in this article is only a special case of inter-process communication. It is also useful for example, process control: to allow a process to kill another process. Of course, this is not within the scope of this article. It doesn't matter if you don't know.

To do things, you must grasp the key points and difficulties, such as chasing girls. The key point is that they cannot be shown at the beginning... Be sure to get along with each other as a friend. It will take a long time to complete the process.

Recently, it was really depressing. On the one hand, there was no breakthrough in technology, and on the other hand, my friends left the company one after another. This made me hard at work and I was not playing after work. Really miserable!

Let's get started with our value transfer journey.

First of all, you need to know that each process has an independent memory space. Therefore, passing values between two processes is a very inefficient and time-consuming process. The advantage of a thread over a process is that it shares a piece of memory. Therefore, the speed of passing values is faster than that of the process. The fastest way is the same thread. These knowledge points are the prerequisite for everyone to understand program value transfer.

In linux, the methods for passing values between processes are as follows:

Pipelines, message queues, signals, shared memory, and APIs.

There are several communication methods between processes in android:

Activity, content provider, binder, service

In fact, the android process communication is based on linux. Although the names are slightly different, the underlying implementation is implemented in the above four methods.

1. Activity implements value transfer between two apps

Suppose there are two apps, APP1 and APP2, and you want to start ActivityB in APP2 through a button in ActivityA in app1 or click events of other controls. The procedure is as follows:

1. Expose ActivityB

For example, if a LoginActivity needs to be exposed, you can modify the manifest.

<Activity
Android: name = "com. saike. android. grape. controller. personal. LoginActivity"
Android: screenOrientation = "portrait"
Android: windowSoftInputMode = "adjustResize | stateHidden">
<Intent-filter>
<Action android: name = "xx.com"/>

<Data android: scheme = "value"/>

<Category android: name = "android. intent. category. DEFAULT"/>
</Intent-filter>
</Activity>

First, I will introduce the functions of the above Code:

I will not talk much about the previous lines, mainly the words in <intent-filter>. In fact, we can see the role of this tag from the name: used to filter intent, so what is intent, I believe it is worth noting that intent is a class that cannot be ignored when values are passed in the Activity.

Before proceeding to the above section, let's take a look at a piece of code that we are familiar:

<Intent-filter>
<Action android: name = "android. intent. action. MAIN"/>

<Category android: name = "android. intent. category. LAUNCHER"/>
</Intent-filter>

This is not familiar to us anymore, because we need to specify the activity for starting an application when writing any application. At this time, we must use the tag action and assign its attribute android: the name is android. intent. action. main

The meaning of this attribute value is similar to that of the "main" function of the program starting from this activity.


Then call the method where we need to start this activity:

Intent I = new Intent ("xx.com", Uri. parse ("value: // 111 "));
This. startActivity (I );

You can.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.