10-Day Learning Android Development (2-1)-Core components activity

Source: Internet
Author: User

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

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.