Android Click the Back button and load activity life cycle record ... Glance

Source: Internet
Author: User

@Override
protected void Onpostcreate (Bundle savedinstancestate) {
Super.onpostcreate (savedinstancestate); To change body of overridden methods use File | Settings | File Templates.
}

@Override
protected void OnStart () {
System.out.println ("---------------onStart---------------");
Super.onstart (); To change body of overridden methods use File | Settings | File Templates.
}

@Override
protected void Onrestart () {
System.out.println ("---------------onrestart---------------");
Super.onrestart (); To change body of overridden methods use File | Settings | File Templates.
}

@Override
protected void Onresume () {
System.out.println ("---------------onresume---------------");
Super.onresume (); To change body of overridden methods use File | Settings | File Templates.
}

@Override
protected void Onpostresume () {
System.out.println ("---------------onpostresume---------------");
Super.onpostresume (); To change body of overridden methods use File | Settings | File Templates.
}

@Override
protected void OnPause () {
System.out.println ("---------------onPause---------------");
Super.onpause (); To change body of overridden methods use File | Settings | File Templates.
}

@Override
protected void OnStop () {
System.out.println ("---------------onStop---------------");
Super.onstop (); To change body of overridden methods use File | Settings | File Templates.
}

@Override
protected void OnDestroy () {
System.out.println ("---------------OnDestroy---------------");
Super.ondestroy (); To change body of overridden methods use File | Settings | File Templates.
}
public boolean onKeyDown (int keycode, keyevent event) {
if (keycode== keyevent.keycode_back && event.getrepeatcount () = = 0) {
Toast.maketext (_context, "clicked Back" OnKeyDown "", Toast.length_long). Show ();
System.out.println ("---------------onKeyDown---------------");
This.onbackpressed ();
return true; Confirm the return
}
return false; Do not allow return
}

@Override
public void onbackpressed () {

Toast.maketext (_context, "clicked Back" onbackpressed "", Toast.length_long). Show ();
System.out.println ("---------------onbackpressed---------------");
Super.onbackpressed ();
}

To put it simply,

When activity starts, the following methods are initiated, in order of precedence

Oncreate->onstart->onresume->onpostresume

When you press RETURN, that is, when you end the activity, the order is:

Onpase->onstop->ondestroy

Android hits the back button and loads the activity life cycle record ... , at a glance

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.