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