Android Knowledge Notes (iv)

Source: Internet
Author: User

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)

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.