Android shares multiple activity processes by sharing user IDs.

Source: Internet
Author: User

Implement multiple applications by sharing user IDsProgramUsing the same process can also make these applications share memory.

1. Process status verification when multiple activities in the same package in the same APK are called

[1] Create a project:

Project name: firstproject

Package: COM. Demo

Default activity: mainactivity

[2] Add a new activity:

Name: secondactivity

[3] modify the layout. Add a button in the mainactivity layout. When you click this button, start secondactivity. Place a textview in the secondactivity layout to prove that secondactivity has been started.

[4] run the program to view the process of the APP:

User: app_36 PID: 8360 name: COM. Demo

[5] click the button to start secondactivity and view the process again:

User: app_36 PID: 8360 name: COM. Demo

Conclusion: The Process List does not change. The two activities run in the same process.

2. Process status verification during activity calls of different packages in the same APK

[1] Move secondactivity to the package com. Demo. Second and change the name in androidmanifest. XML to com. Demo. Second. secondactivity.

[2] run the program and check the process at this time:

User: app_36 PID: 10593 name: COM. Demo

[3] click the button to start secondactivity and view the process status at this time:

User: app_36 PID: 10593 name: COM. Demo

Conclusion: The Process List does not change. The two activities run in the same process. That is, the process name is only affected by the package attribute of the manifset node in androidmanifest. xml.

3. Verify the Process status after modifying the activity process attribute in the same APK

[1] Add the process attribute for secondactivity. Its value is ": ABC". It can also be a string starting with ":". The common name is ": Remote ":

  <ActivityAndroid: Name= "Com. Demo. Second. secondactivity"Android: Process= ": ABC">
</Activity>

[2] run the program and check the process:

User: app_36 PID: 12137 name: COM. Demo

[3] click the button to start secondactivity and view the process status:

User: app_36 PID: 12137 name: COM. Demo

User: app_36 PID: 12303 name: COM. Demo: ABC

Conclusion: There is one more entry in the progress table. Each activity has a process. The secondactivity process name is package name + suffix.

4. Verify the activity process status of different package names in different APK

[1] Run firstproject:

User: app_36 PID: 12137 name: COM. Demo

[2] Create a secondproject:

Project name: secondproject

Package: COM. demo2

Default activity: mainactivity

[3] Run secondproject:

User: app_37 PID: 14191 name: COM. demo2

Conclusion: There is one more entry in the progress table. Each activity has a process, and its process user ID and package name are also different, which does not affect each other.

5. verify the status of activity processes with the same signature and package name for different APK

[1] modify the package of secondproject to com. Demo. Modify androidmanifest. xml accordingly.

[2] Run secondproject to view the process:

User: app_36 PID: 14944 name: COM. Demo

Conclusion: There is only one input table, but the firstproject is actually overwritten at this time, and only the secondproject exists in the system, because the signature keys used by the APK during simulator debugging are the same, and the keys are the same in the system, if the package name is the same, the package is replaced by the firstproject.

You can use ddms to copy/data/system/packages. XML to view the content:

   code highlighting produced by actipro codehighlighter (freeware) 
http://www.CodeHighlighter.com/
--> package name =" com. demo " codepath ="/data/APP/com.demo.apk " System =" false " TS =" 1279955425000 " version =" 1 " userid =" 10036 " >

In this file, the package name is unique, and the user name is determined by userid.

6. verify the status of activity processes with the same package name and different APK signatures

[1] In the eclipse package explorer navigation tree, right-click the firstproject.

[2] Android tools --> export signed application package: Follow the Wizard to create an APK package signed with the specified key.

[3] export the second project.

[4] switch the window to the simulator, press the Home Key --> press the menu key --> set --> Application --> Manage Application --> secondproject --> Uninstall. This is to prepare for installation using the command line.

[5] Start a command line window and run ADB install firstproject.apk. A prompt is displayed, indicating that the installation is successful.

[6] Run ADB install secondproject.apk to prompt installation failure.

Conclusion:

1> the default APK is assigned with a new userid during installation. In this case, the userid of firstproject and secondproject can be considered different.

2> If the package name is different, it doesn't matter whether the signature key is the same. Both APK files can be installed. [4th labs]

3> If the package name is the same, if the signature key is the same, the 5th labs will be overwritten. If the signature is different, the installation of the second APK will fail. [6th labs]

7. Analysis of processes with different package names with the same share user ID and different APK names

[1] modify the manifset node of androidmanifest. xml of firstproject and secondproject to add attributes

 
  Android: shareduserid = "com. deshortname"

 

[2] modify the secondproject package to com. demo2, otherwise it will overwrite firsetproject.

[3] Run firsetproject and secondproject to view the process list:

User: app_35 PID: 19993 name: COM. demo2

User: app_35 PID: 20045 name: COM. demo2

Conclusion:

There are still two processes. However, if the user name of the process is the same, the login userid is valid and the process PID is different.

Export/data/system/packages. xml again and view its content. You can see that the userids of both projects are 10035, which is indeed the same:

  < Package  Name  = "Com. Demo"  Codepath  = "/Data/APP/com.demo.apk"  System  = "False"  TS  = "1279957484000"  Version  = "1"  Shareduserid  = "10035"  >  
< Package Name = "Com. demo2" Codepath = "/Data/APP/com.demo2.apk" System = "False" TS = "1279957473000" Version = "1" Shareduserid = "10035" >

8. Analysis of process attributes of different APK, share user ID, package name, and specified activity

[1] modify the mainactivity process attribute of secondproject and bind it to the process named com. Demo:

 
  <ActivityAndroid: Name= ". Mainactivity"Android: Label= "@ String/app_name"Android: Process= "Com. Demo">

[2] Run firstproject and secondproject to view the process status:

User: app_35 PID: 21387 name: COM. Demo

Conclusion: two activities run in the same process.

9. Different APK files have the same share user ID, different package names, and different signature keys.

After the experiment, the installation of the second APK will prompt the error install_failed_update_incompatible, and the installation fails.

Summary:

Different userids:

Different package names:

When the process attribute is not set, each activity is in its own process. Even if the process specifies the package name, it will not share the process with another user with the same name.

The package name is the same:

Same signature: overwrite the old APK with the same package name. Different signatures: The New APK will fail to be installed. [Signature keys are generally different]

Userid:

Different package names:

When the process attribute is not set, each activity is in its own process. If the process attribute is specified, the process can be shared.

The package name is the same:

Same signature: overwrite the old APK with the same package name. Different signatures: The New APK will fail to be installed. [Signature keys are generally different]

Refer:
[1] http://www.lhzhang.org/post/2010/09/Androide9809ae8bf87e585b1e4baabe794a8e688b7IDe69da5e5ae9ee78eb0e5a49aActivitye8bf9be7a88be585b1e4baab.aspx

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.