Android interview questions (1)

Source: Internet
Author: User

1. Check whether the process of Android dvm is the same concept as that of Linux.

DVM refers to the Virtual Machine of dalivk. Every Android application runs in its own process and has an independent Dalvik Virtual Machine instance. Every DVM is a process in Linux, so it can be considered the same concept.

2. What are the features and differences of animations in android?

Two types: Tween animation and Frame animation. Tween animation, which allows view components to move, zoom in, zoom out, and change transparency. Another Frame Animation, the traditional animation method, it is achieved through sequential playback of arranged images, similar to movies.

3. handler mechanism Principle

Andriod provides Handler and logoff to satisfy inter-thread communication. Handler first-in-first-out principle. The logoff class is used to manage Message Exchange between objects in a specific thread ).

1) loue: A thread can generate a loue object to manage the Message Queue (Message Queue) in this thread ).

2) Handler: You can construct a Handler object to communicate with logoff so as to push new messages to the Message Queue or receive messages sent by logoff from the Message Queue.

3) Message Queue: used to store messages placed by threads.

4) thread: the UI thread is usually the main thread, and Android will create a Message Queue for it when starting the program.

8. Let's talk about the principles of the mvc model and its application in android

MVC (Model_view_contraller) "model _ view_controller ". The MVC application is always composed of these three parts. Event causes the Controller to change the Model or View, or change both. As long as the Controller changes the data or attributes of Models, all dependent views are automatically updated. Similarly, as long as the Controller changes the View, the View will retrieve data from the potential Model to refresh itself.

1. Refresh View:
To refresh, use handle. sendmessage to send information, and then execute invaliate or postinvaliate in getmessage of handle.
2. GC Memory leakage
Cause:
1. The database cursor is not closed
2. When constructing the adapter, the cache contentview is not used
Derivation of listview optimization problems-reduce the creation of view objects, make full use of contentview, you can use a static class to optimize the process of processing getview/
3. Use recycle () to release the memory when the Bitmap object is not in use
4. the lifecycle of objects in the activity is greater than that of the activity.
Debugging method: DDMS ==> HEAPSZIE ==> dataobject ==> [Total Size]
There are other questions. You are welcome to raise this question. It can be the overall architecture and the Hal layer.

To put it bluntly, the following code shows the basic lifecycle of an Activity:

Java code

Public
Class MyActivity extends Activity {
Protected
Void onCreate (Bundle savedInstanceState );

Protected
Void onStart ();

Protected
Void onResume ();

Protected
Void onPause ();

Protected
Void onStop ();

Protected
Void onDestroy ();
}

Public class MyActivity extends Activity {protected void onCreate (Bundle savedInstanceState); protected void onStart (); protected void onResume (); protected void onPause (); protected void onStop (); protected void onDestroy ();}

The activities you write will reload these methods as needed. onCreate is inevitable. During the normal startup of an Activity, they are called in the order of onCreate-> onStart-> onResume, when the Activity is killed, the sequence is onPause-> onStop-> onDestroy. This is a complete life cycle, but someone asks, the program is running and the phone is called, what should I do with this program? If a new Activity is in full screen when it is aborted: onPause-> onStop, onStart-> onResume when it is restored, if the application is interrupted by an Activity whose Theme is Translucent or dicent, it is only onPause and onResume is restored.

The following describes in detail what the system is doing and what we should do:

OnCreate: Create an interface to initialize data.

OnStart: In this step, the user can see and cannot interact with each other.

OnResume: it becomes interactive with the user. (in the activity stack system, you can manage these
At the top of the Activity, after running the pop-up stack, return to the previous Activity)

OnPause: This step is visible but interactive, and the system will stop animation and other CPU-consuming tasks.
We know from the description above that some of your data should be saved here, because at this time
Your program has a lower priority and may be withdrawn by the system. The data stored here should be stored in

OnResume is read out. Note: This method takes a short time because the next
Activities will not be started until this method is completed

Onstop: becomes invisible and overwritten by the next activity

OnDestroy: This is the last method called before the activity is killed. It may be that the external class calls the finish party.
Method or the system can use isFinishing () to temporarily kill it to save space.
Break it. If you have a Progress Dialog online rotation, please go to onDestroy
Drop the cancel. Otherwise, when the thread ends, the cancel method called by Dialog will be discarded.
Abnormal.


OnPause, onstop, and onDestroy, all activities may be killed by the system in three states.
To ensure the correctness of the program, you need to write the code for the persistent layer operation in onPause () and save all the edited content to the storage medium (generally databases ). In actual work, there are also many problems due to changes in the life cycle. For example, if your application starts to run a new thread and the thread is interrupted, you need to maintain the thread, pause, kill, or roll back data, right? Because the Activity may be killed, pay attention to the variables and some interface elements used in the thread. Generally, I use the Android message mechanism [Handler, message] to handle the problem of multithreading and interface interaction. I will talk about this later, because these things are already very big recently, and I will share them with you when I clear my thoughts.

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.