"One" Activity
1. Life cycle
OnCreate: Indicates that activity is being created (this method can do some initial chemical work)
Onrestart: Indicates that the activity is being restarted and is called when the active activity is visible from invisible
OnStart: Activity is being started, activity is visible, but not in foreground, unable to interact with user
Onresume: The activity is already visible, located in the foreground and can interact with the user
OnPause: Indicates activity is stopping
OnStop
Ondestory:
2. Life cycle analysis under abnormal conditions
When the activity terminates in an abnormal situation, the system calls Onsaveinstancestate to maintain the current activity status;
After the activity is re-created, the system calls Onrestoreinstancestate and passes the bundle objects saved as arguments to the OnCreate and Onrestoreinstancestate methods as parameters while the activity is destroyed.
3.activity Load Mode
Standard: Default mode
Singletop: Stack top mode (activity is reused at the top of the stack, not rebuilt): The display page of the push message
Singletask: There will be no duplicate instance in the stack, reuse will dry turn on all the activity to adapt to the scene: The entrance of the program, used in the Start page and the homepage
SingleInstance: Single-instance mode re-opens new task stack adaptation scenarios: Pages separated from the program (Alerts like alarms)
"Two" broadcast
The broadcast can come from the system and can also come from other apps;
Broadcast is divided into orderly broadcasting and disordered broadcasting;
Intent is used to send the broadcast, Broadcastreceiver is to accept the broadcast.
Dynamic registration must wait until the app starts to receive the broadcast, static registration can be implemented without launching the application can also accept the broadcast;
"Three" service
1. Properties of the manifest file
Exported: Whether the representation can be implicitly invoked by another application
Process: Whether you need to run in a separate process
Enable: Whether it can be instantiated by the system
2. How to ensure that the service is not killed
Kill service due to low memory: You can set the return value of the Onstartcommand method to Start_sticky, which means that the service will recover when memory resources are tight and then restore when memory resources are sufficient, or you can set the service as a foreground service with a higher comparison level This will not be killed when the memory resources are tense.
User manual intervention Kill service: The non-mandatory shutdown service, will walk the life cycle, the Ondestory method will be called, you can send a broadcast in this method, restart (for the program more robust, we can open two services, mutual monitoring, mutual start, service a monitor B broadcast to start B, Service B listens on A's broadcast to start a)
Android 2018-side question