Android's understanding about activity

Source: Internet
Author: User

Android ActivityProgram-- Activity carries the view, which is similar to the Controller in MVC.

I have to say that intent (intent) is used to implement activity and other components (including other activities and services. Broadcast, etc. It is a major innovation of Google and a highlight of Android, which reduces the complexity of development. Just like a unified interactive interface, or simply put, intent is a standard that defines the communication between components. To be honest, when I was learning Android, I always liked to compare it with. Net's win form development, and there are many commonalities between them. However, the interaction between components is obviously more intuitive and convenient than Android. However, it may be because the running mode of the developed program is different that this situation is caused.

Here we will talk about using intent for interaction between two intents of the application. If you are familiar with the lifecycle of the activity, you will know, switch from one activity to another (for the moment, we call the previous activity the parent activity and the last activity the child activity ). The parent activity executes onpause ()-> onstop (), and then runs oncreate ()-> onstart () of the Child Activity. However, when you press "return", you will find that the sub-activity executes the ondestory () method, instead of only the onstop () method, that is, the sub-activity has been destroyed at this time, the next time you switch to this type of activity, a new instance is generated. After the response is returned, the parent activity executes onrestart () and so on. That is to say, the instance of the parent activity always exists, and you do not need to call oncreate () again when returning ().

When you perform another experiment, switch to a new activity in the previous sub-activity. You will find that the child activity is not destory like the parent activity above. That is, if an activity acts as the "Source" of another activity, its lifecycle must be longer than that of the activity it jumps. So how does Android do it. We can easily think of a Data Structure-stack. In fact, every time startactivity () is pushed to the top of the stack, the activity "intent" is expected to start. In this way, we can achieve that the activity at the top of the stack first disappears, and the activity below will restart again after it pops. This is also in line with the program logic.

PS: To test the lifecycle of an activity, you only need to repeat the methods that will be used in the activity life cycle (as described in the API) and enable the logging function (log. I ();) to record relevant logs.

Java and. Net:

ViewCodeJava has the following syntax: class life. This, class name. Class. One is an instance of the referenced class, and the other is an object that references the class type of the class (in. net, it should correspond to the type definition, that is, metadata ). The class name. Class is of the class type, and the class and class are not of the same type. This is usually used in reflection. Well, this is similar to type in. net. Maybe it is preemptible. I still think it is more reasonable to call it "type". A type "prototype" is originally represented by "type" in English. And the class is always confused with the class.

Last time I saw an interview question: what type of class is in. Net? Ah! Is it a class type? Reference type? Nima is the keyword of C! What is the result of Java programmers? It should be better than. Net programmers ~



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.