The life cycle of Android activities

Source: Internet
Author: User

Life Cycle Pictures:

650) this.width=650; "src=" http://img.blog.csdn.net/20141127100106218 "/>

To test the main page layout:

: Layout/activity_main.xml

<relativelayout xmlns:android= "http://schemas.android.com/ Apk/res/android "
    xmlns:tools=" Http://schemas.android.com/tools "
    Android:layout_ Width= "Match_parent"
    android:layout_height= "match_parent"
    android:paddingbottom= "@dimen/activity_vertical_margin"
    android:paddingleft= "@dimen/activity_horizontal_margin"
    android:paddingright= "@dimen/activity_horizontal_margin"
    android:paddingtop= "@dimen /activity_vertical_margin "
    tools:context=". Mainactivity


    <button
        android:id= "@+id/button"
        android:layout_width= "match_parent"
        android:layout_height= " Wrap_content "
        android:text=" Start secondactivity "/>


</relativelayout

To test the main page Java code:

Package com.sxt.day04_03;


Import android.app.Activity;
Import android.content.Intent;
Import Android.os.Bundle;
Import Android.util.Log;
Import Android.view.View;
Import Android.view.View.OnClickListener;


public class Mainactivity extends Activity {


@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_main);
LOG.I ("main", "OnCreate ()");
Setlistener ();
}


private void Setlistener () {
Findviewbyid (R.id.button). Setonclicklistener (New Onclicklistener () {
@Override
public void OnClick (View v) {
Intent intent=new Intent (Mainactivity.this, Secondactivity.class);
StartActivity (Intent);
}
});
}


@Override
protected void OnStart () {
Super.onstart ();
LOG.I ("main", "OnStart ()");
}

@Override
protected void Onresume () {
Super.onresume ();
LOG.I ("main", "Onresume ()");
}

@Override
protected void OnPause () {
Super.onpause ();
LOG.I ("main", "OnPause ()");
}

@Override
protected void OnStop () {
Super.onstop ();
LOG.I ("main", "OnStop ()");
}

@Override
protected void OnDestroy () {
Super.ondestroy ();
LOG.I ("main", "OnDestroy ()");
}

@Override
protected void Onrestart () {
Super.onrestart ();
LOG.I ("main", "Onrestatr ()");
}
}

Second second page layout:

: Layout/activity_second.xml

<relativelayout xmlns:android= "http://schemas.android.com/apk /res/android "
    xmlns:tools=" Http://schemas.android.com/tools "
    Android:layout_ Width= "Match_parent"
    android:layout_height= "match_parent"
    android:paddingbottom= "@dimen/activity_vertical_margin"
    android:paddingleft= "@dimen/activity_horizontal_margin"
    android:paddingright= "@dimen/activity_horizontal_margin"
    android:paddingtop= "@dimen /activity_vertical_margin "
    tools:context=". Secondactivity


    <textview
        android:layout_width= "Wrap_ Content "
        android:layout_height=" wrap_content "
        Android: text= "@string/hello_world"/>


</relativelayout>

Second secondary page Java code:

Package com.sxt.day04_03;


Import android.app.Activity;
Import Android.os.Bundle;


public class Secondactivity extends Activity {


@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_second);
}


}

Effect:

650) this.width=650; "src=" http://img.blog.csdn.net/20141127100810506 "/>

650) this.width=650; "src=" http://img.blog.csdn.net/20141127100832596 "/>

This article from "Follow the heart of the other side" blog, declined reprint!

The life cycle of Android activities

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.