One, process
process:
When a program starts for the first time, Android launches a Linux process ( such as the workshop) and a main thread (such as pipelining). By default, all components of the program will run in that process and thread.
<Activity>,<Service>,<receiver> and <provider> have a process property that specifies which processes the component is running in.
The process created by Android by default is the package name of the current app, for example: Com.xhb.app
process Create :
1, Android:process= "Com.test.app"; represents the creation of a new, independent process.
2, android:process= ": Test", indicates the creation of a process based on the original process, Com.xhb.app:test
process level:
1, Foreground processes (Foreground process): required for the user to be currently working. Only a handful of foreground processes exist in a given time period.
2, visible process: There is no foreground component, but it can still affect what the user sees on the screen.
3, service process: is a service running with the StartService () method, and the service does not fall into the above 2 categories
4, background processes (Background process) : is an activity that maintains a current invisible to the user (the OnStop () method that has called the Activity object) (not affected if there are other threads running in addition to the UI thread).
5, empty process: a process that does not maintain an active application component.
Note: It is initialized multiple times when the multi-process app is global initialized (myapplicaion---onCreate), and it needs to be judged to be executed only once.
interprocess communication (IPC):
Messenger:
Aidl:
Between different processes, memory is not shared and communication is required.
Second, the service
By Run location Category:
Category |
Difference |
Advantages |
Disadvantages |
Application |
On-premises Services (local) |
The service is attached to the main process, |
The service is attached to the main process rather than the independent process, thus saving resources to some extent, and the local service because it is in the same process and therefore does not require IPC, nor does it require aidl. The corresponding bindservice will be much more convenient. |
After the main process is killed, the service terminates. |
Very common applications such as: HTC Music Play service, every day music playing service. |
Remote Services (remotes) |
The service is an independent process, |
The service is a standalone process, and the corresponding process name format is the package name plus the android:process string you specified. Because it is an independent process, the service is still running, unaffected by other processes, and has a high degree of flexibility in providing services to multiple processes when the activity's process is killed. |
The service is a standalone process, consumes a certain amount of resources, and uses aidl for IPC to be a little more troublesome. |
Some service providers that provide system services are resident. |
In fact, remote service is very rare, and is generally a system service.
Classification by Run Type:
|
difference |
apply |
front desk Service |
ongoing Notification is displayed in the Notification column, |
|
background service |
default The service is a background service, that is, the ongoing notification is not displayed in the notification column. |
|
Some classmates may ask, backstage service we can create ongoing's Notification by ourselves so as to become the front desk service? The answer is no, the front desk service is required to call STARtFo r ound (andROID 2.0 and later versions) or SETFOR After doing the above work egRound (andROID 2.0 versions) make the service a front-desk service. The advantage of this is that when the service is forcibly terminated externally, the ongoing Notification will still be removed.
Classification by usage:
Category |
Difference |
StartService Start-up services |
Primarily used to start a service to perform background tasks without communication. Stop service using StopService |
Bindservice Start-up services |
This method initiates the service to communicate. Stop service using Unbindservice |
StartService also bindservice start-up service |
Stop service should use both Stepservice and Unbindservice |
Third, notice
Notification Bar
Pendingintent pendingintent = pendingintent.getactivity (this, 0, new Intent (this, servicetestactivity.class), 0);
Notificationcompat.builder Mbuilder =
New Notificationcompat.builder (This)
. Setsmallicon (R.mipmap.ic_launcher)
. Setcontenttitle ("My notification")
. Setcontenttext ("Hello world!");
Mbuilder.setcontentintent (pendingintent);
Notificationmanager mnotifymgr =
(Notificationmanager) Getsystemservice (Notification_service);
Mnotifymgr.notify (1, Mbuilder.build ());
From for notes (Wiz)
Processes, services, and notifications