Android Market-Frame building

Source: Internet
Author: User

After we have learned the basics of Android, we certainly want to build a project of our own based on the basic knowledge we have learned, but we do not know where to start, our topic is to learn the basic knowledge of Android, to practiced hand use.

Our project is a comprehensive application of knowledge by writing an Android market that we often use, which has the following features:

    • 1: There are so few tab, home, category, recommendations and themes
    • 2: The homepage is divided into the upper and lower three sections, respectively, the search, the recommended bar and the app list
    • 3: Category use grid effect display category, click to enter the App list show
    • 4: Recommendation is the use of other people to achieve a recommended effect
    • 5: Theme shows pictures and text descriptions respectively, click to enter and display the app list
    • 6: The slide bar includes options, including settings, profile, check for updates, and download management
    • 7: Multi-threaded download, can be paused, cancel and other operations
    • 8: Other Features

Okay, nonsense, the first thing we need to do now is to review the basics of Android. In our future blog, we will review the basics related to our process.

First, we know that the four components of Android are:

    • 1:activity (Event)
    • 2:service (Service)
    • 3:broadcast Receiver (broadcast)
    • 4:content Provider (content Provider)

Our main memory in this blog post is Android's first component activity and Android application.

We know that when we do Android development, each activity corresponds to a corresponding interface, then each activity corresponds to its own life cycle, first we discuss the activity life cycle, the so-called declaration cycle, Is the process of activity from creation to destruction.

Let's look at the following functions in the Android API about activity's declaration cycle:

@Override    protected void onCreate(Bundle savedinstancestate)        {Setcontentview (R.layout.activity_main); LOG.E ("Activity--->","Create");Super. OnCreate (Savedinstancestate); }@Override    protected void OnStart() {LOG.E ("Activity--->","Start");Super. OnStart (); }@Override    protected void Onrestart() {LOG.E ("Activity--->","Restart");Super. Onrestart (); }@Override    protected void Onresume() {LOG.E ("Activity--->","Resume");Super. Onresume (); }@Override    protected void OnPause() {LOG.E ("Activity--->","Pause");Super. OnPause (); }@Override    protected void OnStop() {LOG.E ("Activity--->","Stop");Super. OnStop (); }@Override    protected void OnDestroy() {LOG.E ("Activity--->","Destroy");Super. OnDestroy (); }

1: First we look at the order in which the function is called when an activity is started:

namely OnCreate ()->onstart ()->onresume ()

2: what function does the two activity call when the first activity initiates another activity?

Let's take a look:

That is Activity1 onPause ()->activity2 onCreate (), Activity2 OnStart (), Activity2 onresume (), Activity1 onStop ()

3: How the function is called when returning from the second activity to the first activity, let's look at:

Activity2 onPause (), Activity1 Onrestart (), Activity1 OnStart (), Activity1 onresume (), Activity2 OnS Top () Activity2 OnDestroy ()

4: When the activity is destroyed, what are the different situations?

First, press the back key to destroy the activity:

Activity OnPause (), Activity OnStop () OnDestroy ()

The second: When process kills, that is, the time to kill

Activity OnPause (), Process kill
or for
Activity OnPause (), Activity onStop (), Process kill

Let's take a look at these several functions in detail:

In our project development, these functions are basically inherited from the parent class.

1:oncreate (): When the activity first starts, the method triggers, and in this function basically completes the activity initialization work. The function has a parameter that is used to save the state when the function onsaveinstance () is saved.

2:onstart (): This function represents the start of the activity, which will show the activity to the user

3:onresume (): This method is triggered when an activity interacts with the user

4:onpause (): This method is triggered when an activity goes from the foreground to the background run

5:onstop (): Triggers the method when an activity does not need to be displayed to the user. But sometimes the function is not triggered and the activity is destroyed, and we just saw three ways the activity was destroyed, so if you want to save the activity state, you can set it in the OnPause () function.

6:onrestart (): The function is called when the Stop state activity is presented to the user again

7:ondestroy (): Triggered when activity is destroyed, but sometimes not triggered and destroyed directly.

What's more, all the activity is managed in the activity stack, and there's no more talking about it.

Let's talk about the application in the Android program.

We will mistakenly think that when the Android program runs, it will run the first activity directly, in fact, this is not true, in fact, a program run, the first will run application. In fact, the operation of an Android program first runs the application OnCreate () function, not the first activity of the OnCreate () function, in an Android program can not activity, But there must be application.

In application, some global variables are often defined for use by other activity. Interested students can learn about application's declaration cycle.

Well, in this article, we'll review some of the basics that we'll be using in a while, and the following blog post will formally start our Android Market development path.

Copyright NOTICE: Hello, reprint please leave my blog address, thank you

Android Market-Frame building

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.