Android Notes (i)

Source: Internet
Author: User

Android System Architecture

Android can be roughly divided into four-tier architectures, five-block areas


1.Linux Core Layer

The Android system is based on the Linux kernel, which provides the underlying drivers for various hardware on Android devices, such as display drivers, audio drivers, camera drivers, Wi-Fi drivers, power management, and more.

2. System Runtime Layer

This layer provides key feature support for Android systems through a number of C + + libraries. such as the SQLite library provides support for the database, opengl| The ES Library provides support for 3D drawings, and the WebKit Library provides support for the browser kernel.

Also on this floor is the Android Runtime Library, which provides some core libraries that allow developers to write Android apps in the Java language. In addition, the Dalvik virtual machine instance is included in the Android Runtime library. Compared to the Java Virtual machine, Dalvik is specifically designed for mobile devices, which are optimized for mobile memory and CPU performance.

3. Application Framework Layer

This layer primarily provides some of the core applications that can be used to build applications using these APIs, and developers can build their own applications by using these APIs. api,android

4. Application Layer

All applications installed on the phone are on this level, such as the system's own contacts, SMS programs, or games that you download from Google Play and, of course, the programs you develop yourself.



Requestwindowfeature (Window.feature_no_title)

Do not show title bar in activity

Note that this code must be executed before Setcontentview (), or it will be an error.



Using the menu in an activity

First create a new menu folder under the Res directory and create a new one under this folder named Main Main.xml


<?xml version= "1.0" encoding= "Utf-8"? ><menu xmlns:android= "Http://schemas.android.com/apk/res/android" >        <item        android:id= "@+id/add_item"        android:title= "add"        />        <item android:id = "@+id/remove_item"        android:title= "Remove"        />        </menu>

    @Override Public    Boolean oncreateoptionsmenu (Menu menu) {        //Inflate the menu, this adds items to the Action bar I F it is present.//        getmenuinflater (). Inflate (R.menu.menu_main, menu);        Getmenuinflater (). Inflate (R.menu.main, menu);        Returns true to allow the created menu to be displayed back to False to create a menu that will not display        return true;    }
    public boolean onoptionsitemselected (MenuItem item) {        switch (Item.getitemid ()) {case            R.id.add_item:                Toast.maketext (This, "You clicked Add", Toast.length_short). Show ();                break;            Case R.id.remove_item:                toast.maketext (This, "You clicked Remove", Toast.length_long). Show ();                break;            Default:        }        return true;    }



    @Override public    void OnClick (View v) {        finish ();    }

Can be used to destroy an activity



Intent (Context packagecontext, class<?> CLS)


An explicit intent

        Intent Intent = new Intent (mainactivity.this, secondactivity.class);        StartActivity (Intent);


Implicit intent

Only one action can be specified in each intent, but it is possible to specify multiple category


            <intent-filter>                <action android:name= "Com.example.activity.ACTION_START"/>                <category Android:name= "Android.intent.category.DEFAULT"/>                <category android:name= "com.example.activity.MY_ CATEGORY "/>            </intent-filter>


Intent Intent = new Intent ("Com.example.activity.ACTION_START"); Intent.addcategory ("Com.example.activity.MY_ CATEGORY "); StartActivity (intent);


Open a Web page by using an implicit intent

Intent Intent = new Intent (Intent.action_view); Intent.setdata (Uri.parse ("http://www.baidu.com")); StartActivity ( Intent);


        <activity android:name= ". Thirdactivity ">            <intent-filter>                <action android:name=" Android.intent.action.VIEW "/>                <category android:name= "Android.intent.category.DEFAULT"/>                <data android:scheme= "http"/>            </intent-filter>        </activity>


Call the system dial-up interface

Intent Intent = new Intent (intent.action_dial); Intent.setdata (Uri.parse ("tel:10086"));


Passing data to an activity down


String data = "Hello secondactivity"; Intent Intent = new Intent (mainactivity.this, Secondactivity.class); Intent.putextra ("Extra_data", data); StartActivity (intent);
Intent Intent = Getintent (); String data = Intent.getstringextra ("Extra_data");


Return data to previous activity

Intent Intent = new Intent (mainactivity.this, secondactivity.class);//1 for Request Code Startactivityforresult (Intent, 1);

Intent Intent = new Intent () Intent.putextra ("Data_return", "Hello mainactivity");//The first parameter is used to return processing results to the previous activity, typically using only result_ OK or result_canceled These two values Setresult (RESULT_OK, intent); finish ();

Since we are using the Startactivityforresult () method to start Secondactivity, the Onactivityresult () method of the previous activity is recalled after Secondactivity is destroyed

So we need to rewrite the Onactivityresult () method in Mainactivity

    /**     * Requestcode Request Code     *    /@Override protected void Onactivityresult (int requestcode, int resultcode, Intent data) {    switch (requestcode) {case    1:    if (ResultCode = = RESULT_OK) {    String returneddata = data.ge Tstringextra ("Data_return");    LOG.D ("Mainactivity", Returneddata);    }    break;    Default:    }    }


Return data by pressing the back key

Overriding the Onbackpressed () method


@Overridepublic void onbackpressed () {Intent Intent = new Intent (); Intent.putextra ("Data_return", "Hello mainactivity") ; Setresult (RESULT_OK, intent); Finish ();}




Android Notes (i)

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.