What's the use of the generated code for the new Android code analysis?

Source: Internet
Author: User

Just start learning, novice, welcome to shoot bricks and despise.

Direct entry, the new version of Android's main code analysis:

1  PackageCom.bslk.helloworld;2
/*1. Here the import package, there will be a warning place, because no use, has been killed, and other regardless, should now 0err0warn*/
/*2. This is some imported package, the specific does not explain, do not tangle, do not understand their own degrees Niang, asked I will despise you * *3 Importandroid.support.v7.app.ActionBarActivity;4 Importandroid.support.v4.app.Fragment;5 ImportAndroid.os.Bundle;6 ImportAndroid.view.LayoutInflater;7 ImportAndroid.view.Menu;8 ImportAndroid.view.MenuItem;9 ImportAndroid.view.View;Ten ImportAndroid.view.ViewGroup; One
/*3. The new version is inherited actionbaractivity, the old version of the tutorial is activity, in order to be compatible, now mandatory use, Baidu will tell you how to change back,
Personally feel that this does not matter, to understand the line, can be used on the line, the administration of his official use of what kind of realization, want to change is their own habit of it about */ A Public classMainactivityextendsactionbaractivity { -
/*4. This is the OnCreate () method that is bound to be called when activity is established,
The first line is the declaration
Then inherit the original OnCreate () method,

The view is then loaded into the Activity_main, which is generally defined in XML */ - @Override the protected voidonCreate (Bundle savedinstancestate) { -/* During the activity's life cycle, as long as you leave the visible phase, or lose focus, the activity is likely to be terminated by the process and killed!
At this time, it is necessary to have a mechanism to preserve the state of the moment, which is the role of savedinstancestate. */
Super. OnCreate (savedinstancestate);
/* Load interface * / - Setcontentview (r.layout.activity_main);18/* Add a placeholder fragment and cut a screen into pieces so that you can display a lot of things like a tablet. Look at this.http://blog.csdn.net/kernel_learner/article/details/8449126* * + if(Savedinstancestate = =NULL) { - Getsupportfragmentmanager (). BeginTransaction () +. Add (R.id.container,Newplaceholderfragment ()). commit (); A } at } -
/* Add Menu */ - @Override - Public BooleanOncreateoptionsmenu (Menu menu) { - - //inflate the menu; This adds items to the action bar if it is present.
/* Add menu items According to the file of the actual menu item * / in getmenuinflater (). Inflate (R.menu.main, menu); - return true; to }32
/* Menu Response * / - @Override the Public Booleanonoptionsitemselected (MenuItem item) { * //Handle Action Bar item clicks here. The Action Bar would $ //automatically handle clicks on the Home/up button, so longPanax Notoginseng //As you specify a the parent activity in Androidmanifest.xml. -/* Get the corresponding ID number of the pressed menu item */
intID =Item.getitemid ();
/* According to the menu ID, make the corresponding response, generated by the settings did not respond, that is, there is nothing to achieve * * the if(id = =r.id.action_settings) { + return true; A }
/* return * / the return Super. onoptionsitemselected (item); + } - $ /** $ * A placeholder fragment containing a simple view. - */
/* This is called in the above placeholder fragment? What the hell, it's like adding multiple fragment to fit the tablet's multi-block display, improving the user experience, and displaying it in a terminal such as a phone. */ - Public Static classPlaceholderfragmentextendsFragment { the - Publicplaceholderfragment () {Wuyi } the - @Override Wu PublicView Oncreateview (layoutinflater inflater, ViewGroup container, - Bundle savedinstancestate) { AboutView Rootview =inflater.inflate (R.layout.fragment_main, container, $ false); - returnRootview; - } - } A +}
Part is not clear, once again learn to perfect it! Ha ha

What's the use of the generated code for the new Android code analysis?

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.