Android Market-framework building and Android framework building

Source: Internet
Author: User

Android Market-framework building and Android framework building

After learning the basic knowledge of android, we certainly want to build an android project by using the basic knowledge we have learned, but do not know where to start, this topic is intended to be used after learning the basic knowledge of Android.

This project is a comprehensive application of knowledge by compiling an Android Market that we often use. This application has the following functions:

  • 1: There are several tabs, home pages, categories, recommendations, and topics
  • 2: The home page is divided into three parts: search, recommendation, and app list.
  • 3: the category uses the grid effect to display the category. Click to display the category in the app list.
  • 4: recommendation is a recommendation result achieved by others.
  • 5. The topic displays the image and text descriptions respectively. Click to display the app list.
  • 6: The slide bar contains some options, including settings, personal homepage, check for updates, and download management.
  • 7. multi-threaded download. you can pause or cancel the download.
  • 8: Other Functions

Well, let's talk about it. The first thing we need to do now is to review the basic knowledge of android first. In our later blogs, we will review the basic knowledge related to our process.

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

  • 1: activity)
  • 2: service)
  • 3: Broadcast Receiver (Broadcast)
  • 4: Content Provider)

In this blog, we mainly recall the first android COMPONENT activity AND android Application.

We know that during android development, every activity corresponds to a corresponding interface, and every activity corresponds to its own lifecycle, first, we will discuss the lifecycle of an activity. The so-called lifecycle is the process from activity creation to activity destruction.

Let's take a look at the following functions in the android api about the activity 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, let's take a look at the sequence of function calls when an activity is started:

That is, onCreate ()-> onStart ()-> onResume ()

2: when the first activity starts another activity, what functions are called by the two activities respectively?

Let's take a look:

Activity1 onPause ()-> activity2 onCreate ()-> activity2 onStart ()-> activity2 onResume ()-> activity1 onStop ()

3: How is the function called when the second activity is returned to the first activity? Let's take a look:

Activity2 onPause ()-> activity1 onRestart ()-> activity1 onStart ()-> activity1 onResume ()-> activity2 onStop ()-> activity2 onDestroy ()

4: when the activity is destroyed, what are the situations?

First, press the return key to destroy the activity:

Activity onPause ()-> activity onStop ()-> activity onDestroy ()

2. process kill, that is, when the process is killed.

Activity onPause ()-> Process kill
Or
Activity onPause ()-> activity onStop ()-> Process kill

The following describes the functions:

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

1: onCreate (): This method is triggered when the activity is started for the first time. Basically, the initialization of the activity is completed in this function. This function has a parameter used to save the status when the OnSaveInstance () function is saved.

2: onStart (): indicates that the activity is started and displayed 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 is transferred from the foreground to the background.

5: onStop (): This method is triggered when an activity does not need to be displayed to the user. However, sometimes the function will not be triggered and the activity will be destroyed. As we have just seen, the three types of activity are destroyed. Therefore, if you want to save the activity status, you can set it in the onPause () function.

6: onRestart (): This function is called when the stopped activity is displayed to the user again.

7: onDestroy (): triggered when the activity is destroyed, but sometimes it is not triggered and destroyed directly.

In addition, all activities are managed in the activity stack.

Let's talk about the Application in the android program.

We will mistakenly think that the first activity will be directly run when the android program runs. In fact, this is not correct. In fact, the application will be run first when a program runs. In fact, the first running of an android program is the onCreate () function of the Application, rather than the onCreate () function of the first Activity. In an android program, there can be no activity, however, you must have an Application.

In Application, global variables are often defined for other activities. If you are interested, you can learn about the Application declaration cycle.

Well, in this article, we will first review some basic knowledge we will use for a while. The next blog will officially start our android Market development path.

Copyright Disclaimer: Hello, please leave the address of your blog for reprinting. Thank you.

Related 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.