Android Custom View Quest (i)-life cycle

Source: Internet
Author: User

Activity code:

public class Fiveactivity extends Appcompatactivity {private MyView MyView;        @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);        LOG.E ("Log", "Activity life cycle: OnCreate");        Setcontentview (r.layout.activity_five);    Initview ();    } private void Initview () {MyView = (MyView) Findviewbyid (R.id.my_view);        } @Override protected void OnStart () {Super.onstart ();    LOG.E ("Log", "Activity life cycle: OnStart");        } @Override protected void Onresume () {super.onresume ();    LOG.E ("Log", "Activity life cycle: Onresume");        } @Override protected void Onrestart () {Super.onrestart ();    LOG.E ("Log", "Activity life cycle: Onrestart");        } @Override protected void OnPause () {super.onpause ();    LOG.E ("Log", "Activity life cycle: OnPause");        } @Override protected void OnStop () {super.onstop ();    LOG.E ("Log", "Activity life cycle: OnStop"); } @Override   protected void OnDestroy () {Super.ondestroy ();    LOG.E ("Log", "Activity life cycle: OnDestroy"); }}

Custom View Code:

public class MyView extends View {public MyView (context context, AttributeSet Attrs) {Super (context, attrs);    LOG.E ("Log", "OnCreate");        } @Override protected void Onfinishinflate () {super.onfinishinflate ();    LOG.E ("Log", "Onfinishinflate");        } @Override protected void Onattachedtowindow () {Super.onattachedtowindow ();    LOG.E ("Log", "Onattachedtowindow"); } @Override protected void onmeasure (int widthmeasurespec, int heightmeasurespec) {super.onmeasure (widthmeas        Urespec, Heightmeasurespec);    LOG.E ("Log", "Onmeasure"); } @Override protected void onsizechanged (int w, int h, int oldw, int oldh) {super.onsizechanged (W, H, OLDW,        OLDH);    LOG.E ("Log", "onsizechanged");  } @Override protected void OnLayout (Boolean changed, int l, int t, int r, int b) {super.onlayout (changed, L,        T, R, b);    LOG.E ("Log", "OnLayout"); } @Override protected void OnDraw (Canvas canvAs) {Super.ondraw (canvas);    LOG.E ("Log", "OnDraw"); } @Override public void Onwindowfocuschanged (Boolean haswindowfocus) {super.onwindowfocuschanged (HASWINDOWFO        CUS);    LOG.E ("Log", "onwindowfocuschanged" + "" + Haswindowfocus); }}

Android Custom View Quest (i)-life cycle

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.