Getting Started with Android's zero-single-row development diary (iv) activity of--android four components

Source: Internet
Author: User

In Android, whether it is the developer or the user, the most contact is even activity. It is the most complex and core component of Android. The activity component is the component responsible for interacting with the user, and its design philosophy is similar in many ways to a Web page. Of course, this similarity is mainly embodied in the idea of design. In terms of implementation, Android's activity component has its own design specifications, and it makes it easier to use local resources such as threading, file data, and so on.I. Life cycle of Activity

The Activity's life cycle is controlled by the following functions.

1  Public classActivityextendsApplicationContext {2       protected voidonCreate (Bundle icicle);3       protected voidOnStart ();4       protected voidOnrestart ();5       protected voidOnresume ();6       protected voidOnfreeze (Bundle outicicle);7       protected voidonPause ();8       protected voidonStop ();9       protected voidOnDestroy ();Ten}
    1. OnCreate function: The function is where you initialize, this is the place to execute the Setcontentview (view) function, the Setcontentview (view) function can be passed into an XML UI interface, you can make the UI and concrete implementation completely separate.
    2. OnStart function: This method is called after the OnCreate () method.
    3. Onrestart () function: Called when Activity transitions from the Stop state to the active state.
    4. Onresume () function: Called when Activity transitions from the Pause state to the active state.
    5. Onfreeze () Function: This method is called when your activity is paused and other activity resumes interacting with the user (before other activity shows)
    6. OnPause () function: Called when the system is about to start a different activity (before other activity displays)
    7. OnStop () function: Called when another activity resumes and obscures the activity, causing it to be no longer visible to the user.
    8. OnDestroy () function: The last method that is called before your activity is destroyed.

Ii. Configuration of Activity
    1. Registration activity, in addition to the system automatically generated activity, other activity must be registered in the Manifest.xml file
      <activity android:name= ". Demo "android:label=" @string/app_name ">//. Demo is to register the activity name, of course not in the default package, the front to add the package name. The following is the name of the activity </activity>
    2. Start another activity
      Intent Intent =new Intent (currentactivity.  this, otheractivity. class ); StartActivity (intent);

      Of course otheractivity must also be registered in the Manifest.xml file. Where intent is a communication mechanism, this will be specifically introduced later.

Iii. some skills on Activity
  1. Lock the operating direction of the activity screen
    <activity android:name= ". EX01 " android:label=" @string/app_name "  android:screenorientation=" Portrait ">//  Vertical screen with a value of landscape for horizontal screen </activity>
  2. Full-screen activity
     //  set full-screen mode  Span style= "color: #000000;"  > GetWindow (). SetFlags (WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);  //  remove title bar  requestwindowfeature ( Window.feature_no_title); 
  3. Add a progress bar to the title of the activity
    // Unclear progress bar requestwindowfeature (window.feature_indeterminate_progress);  Setcontentview (r.layout.main);  Setprogressbarindeterminatevisibility (true);   // Clear progress bar requestwindowfeature (window.feature_progress);  Setcontentview (r.layout.main);  Setprogress (5000);
Activity also has a lot to explain in detail, such as its interactive events, the construction of menus, dialog boxes and other additional interactive resources, and its data structure and so on. We will certainly encounter these in the future study. So I'm not going to go into it here today, just to let you know about its simple mechanism.Reference article: (1) Android activity life cycle http://www.cnblogs.com/draem0507/archive/2012/11/28/2793332.html(2) Detailed Android Activity components http://www.ibm.com/developerworks/cn/opensource/os-cn-android-actvt/CPACMContact information: QQ 348515494 (Please specify the blog park)
Source: (http://www.cnblogs.com/cpacm/p/3900557.html)
Copyright notice: The copyright of this article is owned by the author and the blog Park. Welcome reprint read, reprint must indicate the detailed link of this article.

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.