Process agnostic feature

Source: Internet
Author: User
Tags keep alive
Being one of the most eye-catching terms today, Android has creative features. the most revolutionary one, in my opinion, is process agnostic. this is not a term used in official document, but I prefer to use it since it implies this feature well enough.
One of center feature of Android is the ability to easily make use of components of other applications. it's a common feature among extends other systems, so how "easy" is Android to distinguish it from others?
Let's first check out how others do. generally, there are two common ways to reuse components. first, the component Author can distribute the component as a library (e.g. DLL, Lib, so, a) that can be called by others. in this way, the reused component becomes part of the application that uses it.
The second way is the shared component runs in a process, and the application wants to use it employs a IPC mechanic to communicate with the hosting process to make use of the component indirectly.
Either way, we programmers must know explicitly the way we're using. And we have to pay attention to or even control the life cycle of the hosting process.
Now let's look at what's different in Android. in Android, components reuse and collaboration are driven by intent. whenever you want to make use of another component, you need to create a intent object. and state your purpose by setting corresponding properties of the intent object. then, you pass the intent to the application framework with startactivity, startservice etc. upon grouping an intent, the application framework determines the best component for processing the intent, and asks for the user if there are multiple components can handle the intent. after a component is identified for handling the intent, an instance of the component will run. the instance may resides in the same process or in a different process with the sender of the intent. from a user's perspective, this procedure is transparent. it doesn' t make difference if the component is running in another process.
The coolest thing is Android also achieves process agnostic feature for end user's experience. if you dismiss current activity, Android guarantees you'll return to the previous activity you worked on. consider the following scenario, application a is showing activity X. then the user clicks a button on activity X and starts a new activity Y from application B which runs in a different process. if, we say, when the user is still working on activity Y, the process that application a runs in dies for some reason, the user doesn' t get affected and can continue with his work until he dismiss activity Y. at this time, the actitymanager notices that activity X doesn't exist, and a new instance will be created and shown. the user will still see activity X as if nothing happened. but it's not guaranteed that activity X's state is maintained correctly unless we write code to persist and restore State at right time.
Needless to say, If components from different process need To talk to each, they still have to employ some kind of IPCS because Android builds on Linux and uses the same underlying process model. the great thing Android does for us is it hides the IPC details from us so that we can use Consistent API With less concern about complicated IPC things.
Another benefit of this design is it'll be Much easier to replace a component , Even if the component is a system built-in one. for example, if your application declares an intent-filter for view action for contact, it will be considered as a valid replacement for built-in contacts application by the system. our application isn't just a second-class citizen anymore.
The process agnostic feature ensures the openness of Android, it also helps making components more loosely coupled to each other.
Besides what was mentioned, it's also important to notice that Process life cycle is managed by the System Automatically. the process may still keep alive after the last activity of it has been dismissed. it's also possible that the process of an inactive activity that you haven't worked for a period of time but not yet closed is terminated by the system on demand for more resources for other processes. we know that. net Framework is called a managed environment because it manages components and memories for us, Android takes a larger step forward by managing process life cycle as well. in this sense, it's a super managed system.
Generally speaking, in android we mainly focus on the components and how they collaborate to accomplish our goal. less concern need to be paid on the technology details that we can't easily ignore on other platforms.

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.