Activity, Service, broadcast Receiver, Content provide are the four core components of Android, Activity is a window that interacts with the user in three states: Run, pause, stop
Seven methods:
protected voidOnCreate(BundleSavedinstancestate);
protected voidOnStart();
protected voidOnrestart();
protected voidOnresume();
protected voidOnPause();
protected voidOnStop();
protected voidOnDestroy();
Life cycle diagram, see:
Http://developer.android.com/reference/android/app/Activity.html
can see:
Running status: In Onresume after
paused state: OnPause after the pause state, if there are other higher priority programs that require memory to run, this program may be stopped, freeing up memory
onpause- " Onresume
Onstop->>onstart
Tip: Adjust the window (code) font size
Windows à Preference à General->appearance->colorsand fonts->text Font à Edit
Case DAY2-1:
1) New Android application Project
2) Create a new class Show1,
activity superclass :activity "
androidmanifest.xml
androidmanifest.xml applicationnodes, "Add"- androidmanifest.xml Add a line:
<activity android:name= "Show1" ></activity>
4) Add a new class layout
GiveNewclass, add a content layout, right-click:Res->layout, addingAndroidxml File,name is: Show1,Layout method:LinearLayout
Add a text:
<textview
Android:id= "@+id/txtmyview"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:text= "MyView"/>
5) new class and content layout bindings, add Setcontentview (R.LAYOUT.SHOW1) to the new class code file as follows:
public class Show1 extends Activity {
@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.LAYOUT.SHOW1);
6) in the main page layout, add the button event, passing the string to Show1:
public class Mainactivity extends Actionbaractivity {
Private Button btnstart;
@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_main);
Btnstart= (Button) Findviewbyid (R.id.butstart);
Btnstart.setonclicklistener (New View.onclicklistener () {
@Override
public void OnClick (View v) {
Intent i=new Intent (mainactivity.this,show1.class);
Bundle Data=new Bundle ();
Data.putstring ("txt", "Hello Show1");
I.putextras (data);
Startactivityforresult (i,0);
Finish ();//If this is the case, the page will be closed
}
});
}
7) Accept the string in the Show1 class:
txtmyview.settext (TXT);
}
}
This article is from "Blue Sea Tactics" blog, please make sure to keep this source http://wanxl.blog.51cto.com/2129901/1587964
10-Day Learning Android Development (2-1)-Core components activity