Android: How to transfer value activity between two apps

Source: Internet
Author: User

Two applications between the value, in fact, the title is too water, the professional argument is "two process how to pass the value", what?! It's not professional enough, okay, you're kinky! "Interprocess communication" is actually more professional, this time you always satisfied! Incidentally, abbreviated to IPC:inter-process communication.

Brothers, if you find this article from search engines or other sources, it means that your Android technology has been elevated to a very high level. Oh, hey, why do you say that? because no matter which platform, thread and process are the absolute focus and difficulty.

This article says that interprocess transfer is only a special case of interprocess communication, and there are other uses, such as Process Control: let one process kill another process. Of course, this is not within the scope of this article, we do not know that it does not matter.

Do things to grasp the focus and difficulties, like chasing girls, the focus is the beginning can not show it ... Must be a friend of the identity of good to get along, waiting for the time to mature smoothly Cheng Zhang. Alas, is my personal experience, we must warning!

Recently really depressed, on the one hand there is no special breakthrough in technology, on the other hand, friends have left, make me work boring, no one to play after work. How miserable!

No more nonsense, let's start our journey of value-added.

First of all, we need to know that each process has a separate memory space, so the two-process transfer between the value itself is inefficient, more time-consuming process. The advantage of a line threads over a process is that it shares a memory, so it is faster to pass the value than the process, and the fastest is of course the same thread. These knowledge points are the prerequisites for everyone to understand the value of the program.

There are several ways to transfer values between processes in Linux:

piping (pipe), Message Queuing, Signal, shared Memory, socket interface.

There are several ways to communicate between processes in Android:

Activity,content Provider,binder,service

In fact, the inter-process communication between Android is built on Linux, although the name is slightly different, but the bottom-up implementation still through the above four ways.

1.Activity implements value transfer between two apps

Suppose you have two apps APP1 and APP2, and you want to start APP2 in Activityb by clicking on a button in the Activitya in App1 or another control's click event. The steps are as follows:

1. Exposing the Activityb

For example, now that a loginactivity needs to be exposed, you can modify the manifest to achieve

<activity            android:name= "com.saike.android.grape.controller.personal.LoginActivity"            android: screenorientation= "Portrait"            android:windowsoftinputmode= "Adjustresize|statehidden" >            < intent-filter>                <action android:name= "zhudows.com"/>                <data android:scheme= "info"/>                <category android:name= "Android.intent.category.DEFAULT"/>            </intent-filter>        </activity >

, the function of the above code I first do an introduction:

The first few lines of I do not say much, mainly <intent-filter> inside that a few words, in fact, from the name can see the role of this tag: for filtering intent, then intent is what, I believe also do not have to say more, Intent is a class that cannot be ignored when passing values in an activity.

Before we take this paragraph, let's look at some of the more familiar pieces of code:

<intent-filter>                <action android:name= "Android.intent.action.MAIN"/>                <category android: Name= "Android.intent.category.LAUNCHER"/></intent-filter>
This is more familiar to us, because when we write any application, we have to indicate the activity of the launch application, we must use the tag action and assign his property android:name to Android.intent.action.main

The value of this property probably means something like the "main" function that represents the program that starts with the activity.


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

Intent I = New Intent ("zhudows.com", Uri. Parse ("info://111")) ;  

This . StartActivity(i);  

Can.




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.