1. Design ideas of complete exit activity
1.1 Encapsulating a basic activity class
Public abstract class RootActivity extends fragmentactivity{
1.2 defining a broadcast listener
Private Intentfilter filter = new Intentfilter (finish_action);
private Broadcastreceiver receiver = new Broadcastreceiver () {
@Override
Public void OnReceive (context context, Intent Intent) {
finish ();
}
};
1.3 Registering in OnCreate and unregistering in OnDestroy
Registerreceiver (receiver, filter);
Unregisterreceiver (receiver);
1.4 Sending broadcasts when used
Intent Intent = new Intent ();
intent.setaction (rootactivity.finish_action);
Ctx.sendbroadcast (intent);
2. Android Force Quit App
Android.os.Process.killProcess (Android.os.Process.myPid ());//exit the current process
System.exit (0);//exit JVM, clear resources
Note: If there is only killprocess, and no system.exit, there may be cached processes in the background
System.exit (0), the difference between system.exit (1):
Parameters 0 and 1 represent the state of exit, 0 indicates a graceful exit, and 1 indicates an abnormal exit (as long as a non-0 exception exits), which simply notifies the operating system that the program is quitting normally.
3, Setcanceledontouchoutside (FALSE) Settings dialog click on the screen does not disappear;
4. About context
Context is an abstract class, Activity, Service, application are all sub-classes of the context.
Activity\service\application are system-provided components that cannot be actively new, so a context is needed to manage contextual relationships;
Android Knowledge Notes (iv)