Android Studio Getting Started--001 Android basic details

Source: Internet
Author: User

Android Studio

Approximate framework:

1.Activity at present,android structure = = = activity + response events within the activity

2. activities First in java->com.example ... and then create an activity under the Androidmanifest.xml Activities to be registered in the app effective in the program.

3. Add a layout to the activity and create a new layout under layout .

1.toast--- a text prompt appears at the bottom of the screen (it will automatically disappear for a certain time).            When using this, the first thing to consider is the trigger condition, which is directly similar to the listener event . Create a toast object from the static method Maketext (context,text,time) , and then call Show () shows up just fine.

2.Menucan save a lot of space create a new foldermenu->build another one .MainMenu File<item>used to create a menu item at least one for each menu itemID"Unique identifier" onetitle"Displays the name of the specified menu---display Name "and then in the correspondingActivityunder rewriteOncreateoptionsmenu ()method, this method first needs to obtain themenu. Mainmenu file. Public booolean Oncreateoptionsmenu (Menu menu) {Getmenuinflater (). Inflater (R.menu.main,menu); return true;}Gets the menu fill object, and then calls theInflaterfunction Fill Menu:Inflatertwo parameters, the first one is to specify which resource file to use to create the menu, and the second specifies which one to add to theMenuobject. Returntrueindicates that the menu is allowed to display,falseindicates not allowed. Response MenuItem, overridingonoptionsitemselected ().

3. destruction activity is just finish () It's good ---- add Finish () to the response listener , which is called automatically when triggered Finish () destruction activity.

4.Intent This feeling is a very important thing, after all, it undertook an activity switch and the transfer of activity data responsibility.

Intent is divided into two kinds of display Intent and implicit Intent .

1-> Display Intent Intent (CONTEXT,CLASS)--- the first parameter requires the context of a startup activity, and the second parameter is the activity that you want to start. Intent Intent (firstactivity.this,secondactivity.class);

startactivity (intent); intent "passed to start Activity When you click the button you can switch to second Activity

2-> implicit intent &NBSP;&NBSP, intent action Span style= "font-family: Arial" >, category "behavior, category" In the system to find the corresponding activity intent

in this case, you need to add an action under the androidmanifest.xml of The registered activity,   Category two properties. You can also use implicit Intent to open a third-party app "apps for other programs"!!!!!!

3-> uses Intent to pass data PutExtra () . in the firstactivity to pass a string inside a function::

String Data= "with no patience";

Intent intent=new Intent (firstactivity.this,secondactivity.class);

Intent.putextra ("Extra_data", data);

StartActivity (Intent);

Accept a string inside a secondactivity

Intent intent=getintent ();

String Data=intent.getstringetra ("Extra_data");

LOG.D ("secondactivity", data);

// In this simple example, the previous activity passed a intent intent extra_data "accepts in response activities intent intent The information carried is displayed. Here it feels intent Like a part-time transporter, One of them is responsible for shipping data putextra () equivalent to goods, getstringextra () extra_data

4-> return data to previous activity

Intent intent=new Intent (first.this,second.class);

Startactivityforresult (intent,1);// The second parameter is the request code, in the back

Create a intent when you start the secondactivity and then second the activity with destruction activities simple to pass the parameters.

Intent intent=new Intent ();

Intent.putextra ("Extra_data", "Hello");

Setresult (result_ok,intent);

The first parameter is used to return the result of the processing up, and the second is to return up Intent

Finish ();

The rest is the need to accept Intent 's message in first activity. "Unspoken rules: Using start activity for Result () The activity that is started will call the last activity after it is destroyed. Onactivityresult () method, you can get the data you want as long as you rewrite it in a way. "

Protect void Onactivityresult (int requestcode,int resultcode,intent data) {

Switch (Requestcode) {

Case 1:

if (RESULTCODE==RESULT_OK) {

String Data=data.getstringextra ("Extra_data");

LOG.D ("firstactivity", data);

break;

Default;

}

when the activity is destroyed, the default return to the previous level will say that you can see the printed message.


Android Studio Getting Started--001 Android basic details

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.