650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/53/7E/wKioL1RpZyCQrWqoAACkJvLzHVo606.jpg "style=" float: none; "title=" 1.jpg "alt=" Wkiol1rpzycqrwqoaackjvlzhvo606.jpg "/>
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/53/80/wKiom1RpZqyCR_IAAAB7HdIdDEc995.jpg "title=" 2.jpg " alt= "Wkiom1rpzqycr_iaaab7hdiddec995.jpg"/>
Interface 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= " Com.example.activity_05.MainActivity " > <TextView android:id= "@+id/textview1" android: Layout_width= "Wrap_content" android:layout_height= "wrap_content " android:text= "@string/hello_world" /> <Button android:id= "@+id/button1" android:layout_ Width= "Fill_parent" android:layout_height= "Wrap_content" android:layout_below= "@+id/textview1" android:layout_margintop= "22DP" android:text= "Start a second activity" /></RelativeLayout>
Interface Second.xml
<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "Android:layout_width=" Match_parent "android:layout_height=" match_parent "android:orientation=" vertical " > <textview android:id= "@+id/textview1" android:layout_width= "Fill_parent" android:layout_he ight= "Wrap_content" android:text= "This is the second activity"/></linearlayout>
maina Ctivity.java
package com.example.activity_05;import android.support.v7.app.actionbaractivity;import android.content.intent;import android.os.bundle;import android.view.menu;import android.view.menuitem;import android.view.view;import android.widget.button;import Android.view.view.onclicklistener;public class mainactivity extends actionbaractivity {private Button button; @Override protected void oncreate (bundle savedinstancestate) { super.oncreate (savedinstancestate); system.out.println (" Mainactivity oncreate: Execute "When the activity is first invoked"); setcontentview (r.layout.activity_main); button = (button) Findviewbyid (r.id.button1); &nBsp; button.setonclicklistener (New onclicklistener () {@Overridepublic void onclick ( VIEW&NBSP;V) {intent intent = new intent (); Intent.setclass (MainActivity.this, Secondactivity.class); MainActivity.this.startActivity (intent);}}); } @Override protected void OnStart () { system.out.println ("mainactivity Onstart:activity is in the visible state when called "); super.onstart (); } @Override protected void onrestart () { system.out.println ("Mainactivity onrestart:activity can get user focus again when called"); system.out.println (This method is called when the second activity is returned to the first activity); SYSTEM.OUT.PRINTLN ("Then call the Onresume method can be displayed"); system.out.println ("and then call the ONS of the second activityTop, OnDestroy. The second activity was destroyed "); super.onrestart (); } //above three methods after execution, this activity can be used @Override protected void onresume () { System.out.println ("Mainactivity onresume"); super.onresume (); } @Override protected void onpause () { system.out.println ("Mainactivity onpause"); system.out.println ("This method of the current activity is called if an activity is started while performing the current Activity"); SYSTEM.OUT.PRINTLN ("Then call the OnCreate, OnStart, Onresume" of the newly launched activity in turn); &NBSP;&NBSP;&NBSP;&NBSP;SYSTEM.OUT.PRINTLN ( "Then call the first activity's OnStop method"); super.onpause (); } @Override protected void onstop () { System.out.println ("Mainactivity onstop"); super.onstop (); } @Override protected void OnDestroy () { system.out.println ("Mainactivity ondestroy"); super.ondestroy (); }}
secon Dactivity.java
Package com.example.activity_05;import android.app.activity;import android.os.bundle;public class secondactivity extends activity {@Overrideprotected void oncreate ( bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.second);} @Overrideprotected void onstart () {system.out.println ("Secondactivity onstart"); Super.onstart ();} @Overrideprotected void onrestart () {system.out.println ("Secondactivity onrestart"); Super.onrestart ();} @Overrideprotected void onresume () {system.out.println ("Secondactivity onresume"); Super.onresume ();} @Overrideprotected void onpause () {system.out.println ("Secondactivity onpause"); Super.onpause ();} @Overrideprotected void onstop () {system.out.println ("Secondactivity onstop"); super.onstop ();} @Overrideprotected void ondestroy () {system.out.println ("Secondactivity&nbSp;ondestroy "); Super.ondestroy ();}}
Androidmanifest.xml
<activity android:name= ". Secondactivity "Android:label=" a second activity "/>
The log output is as follows
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/53/81/wKiom1RpZ0zAZVjeAAiNlG_UNMA234.jpg "title=" Qq20141117110008.png "alt=" Wkiom1rpz0zazvjeaainlg_unma234.jpg "/>
This article is from "Avatar" blog, please make sure to keep this source http://shamrock.blog.51cto.com/2079212/1577328
The life cycle of Android learning note-activity