Http://wear.techbrood.com/guide/components/processes-and-threads.html
Each Android app will start a process by default unless you use Android:process to implement multiple processes.
Each process has a Dalvik virtual machine instance to execute the code.
In the process, there is only one main thread (UI thread), and the 4 components are running in the UI thread by default, so there is no time-consuming operation in the 4 large components, otherwise it will be ANR.
In service and Broadcastreceiver, a separate thread must be opened to do the time-consuming operation.
But when you press the back key to exit the app, when does the process get recycled??
Android will take as long as possible to keep an app process from being recycled, so that the next time it can be started quickly, the process is recycled only when memory is tight, and which processes are recycled based on the priority of the process.
There are 5 process priorities by default, judging by the state of the components in the process:
1 Foreground Process
In simple terms, the process of interacting with users at the foreground is the highest priority.
2 Visible Process
Visible but not interacting with the user
3 Service Process
Not 1 and 2 but contains a process that starts with a startservice service.
4 Background Process
Non-1 2 3 invisible process
5 Empty Process
Empty process, mostly done cache.
Android Push is the socket communication in the service, the process priority is 3, so the memory is also likely to be killed when there is no push to receive.
The service can be set as the foreground process through Startforground (), so that the priority becomes 1 and is not easily killed. and the return value via Onstartcommand
You can control whether a process needs to be restarted if it is accidentally killed, so that it runs for a long time, the application is always online, and a TCP long connection is used for push.
See some people using System.exit (0) and process.killprocess to kill the process, these 2 methods can kill the process, but in some cases will cause the application to restart, such as
When a starts B you call System.exit (0) or process.killprocess in B, it will kill the current process and then restart a new process.
As I said before, 90% of the time you don't need to kill an app manually, so the second boot must be very slow. The process is managed by the OS bottom, and exiting the app you just need to
Finish off all the activity on the line. If there is a need to kill the process, the above 2 methods can be, if only one activity in the task station is called again. Anyway I'm currently
Have not encountered the need to quit every time the application must kill the process of the scene, do not tell me to save memory, said 5 process level, the system itself will be managed, do not need human intervention.
And you kill yourself. The second time you start the process and you need to create a new process, the app starts very slowly.
When is the Android process destroyed?