Android Q &

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 is the role of the SIM card EF file?
Sim card file systems have their own specifications, mainly to communicate with mobile phones, sim itself can have its own operating system, EF is used for storage and communication with mobile phones
3. What are the features of Memory Management in the embedded operating system?
Webpage, segment, and segment pages, using MMU, virtual space, and other technologies
4. What is an embedded real-time operating system? Does the Android operating system belong to a real-time operating system?
An embedded real-time operating system can accept and process external events or data at a high speed, the processing result can control the production process or quickly respond to the processing system within the specified time, and control all real-time tasks to coordinate and operate in an embedded operating system. It is mainly used for industrial control, military equipment, aerospace and other fields with demanding system response time requirements, which requires the use of real-time systems. It can be divided into soft real-time and hard real-time. android is based on the Linux kernel, so it is soft real-time.
5. How many bytes does the longest Short Message count?
70 Chinese characters (including punctuation marks), 160,160 English bytes.
6. 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.
7. 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
Android officially recommends that the mvc mode be used for application development. What is mvc?

Mvc is short for model, view, and controller. mvc consists of three parts:

L model object: it is the main part of an application. All business logic should be written in this layer.

L view object: the part of the application that generates the user interface. It is also the only layer that users can see in the entire mvc Architecture. It receives user input and displays processing results.

L controller (control) objects: controls the display of user interface data and updates the state of model Objects Based on user input. A more important navigation function of controller is that, if you want to use user-related events, you can submit them to m for handling.

Android encourages weak coupling and Component Reuse. In android, mvc is embodied as follows:

1) view layer (view): it generally uses xml files to describe the interface, which can be easily introduced during use. Of course, if you know more about android, you can think of using javascript + html as the view layer in android. Of course, communication between java and javascript is required. Fortunately, android provides convenient communication between them.

2) control layer (controller): The re-authorization of the control layer of android usually falls on the shoulders of many acitores. This statement also implies that you should not write code in acitivity, another reason for this is that the response time of acitivity in android is 5 s. If time-consuming operations are put here, programs are easily recycled.

3) model layer: database operations and network operations should all be processed in the model. Of course, operations such as business computing must also be placed in this layer.
 
 
9. Activity Lifecycle
Like applications on other mobile platforms, the lifecycle of Android applications is under unified control.
That is to say, the fate of the application we write is in the hands of others (systems). We can only learn and
Adapt to it.
To put it simply, why is this: when we run an application on our mobile phone, we may call in.
The program will be interrupted when the SMS is sent or there is no power, and the basic functions of the service phone are prioritized.
The external system does not allow you to occupy too many resources. At least ensure the phone function, so when resources are insufficient
Can be killed.
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, the Android message mechanism [Handler, message] to handle the problem of multithreading and interface interaction.
10. Change Activity to a window: Activity attribute setting
It's easy to talk about it. Some people may want to make the app something floating on the main interface of the mobile phone.
You only need to set the Activity topic to define the Activity in AndroidManifest. xml.
Local sentence:
Xml Code
 
Android: theme = "@ android: style/Theme. Dialog"
Android: theme = "@ android: style/Theme. Dialog"
This makes your application pop up in the form of a dialog box, or
Xml Code
 
Android: theme = "@ android: style/Theme. Translucent"
Android: theme = "@ android: style/Theme. Translucent"
It becomes translucent. [friendly reminder -. -] attributes of similar activities can be found in android. r. the AndroidManifestActivity method of the styleable class shows AndroidManifest. for more information about the attributes of all elements in xml, see android. r. styleable
The above is the property name. The specific value is in android. r. style, such as @ android: style/Theme. dialog "corresponds to android. r. style. theme_Dialog, (replace '_' '. '<-- Note: The content of this article is not a smiley face. You can use it in the description file to find the ing between the class definition and the description file.
11. What should I do if my background Activity is recycled by the system: onSaveInstanceState?
When one Activity A in your program is running, it actively or passively runs another Activity B
At this time, A will execute
Java code
 
Public
Void onSaveInstanceState (Bundle outState ){
Super. onSaveInstanceState (outState );
OutState. putLong ("id", 1234567890 );
}
B will come to A again after completion. There are two situations at this time: A is recycled, and A is not recycled.
The onCreate () method must be re-called for the received A. It is different from directly starting the onCreate () method with parameters.
SavedInstanceState. If it is not recovered, it will be onResume.
SavedInstanceState is a Bundle object. You can basically regard it as a Map object maintained by the system. You may use it in onCreate (). If onCreate () is started normally, it will not be available. Therefore, you need to determine whether it is empty when using it.
Java code
 
If (savedInstanceState! = Null ){
Long id = savedInstanceState. getLong ("id ");
}
Just like in the official Notepad tutorial, if you are editing a note that is suddenly interrupted, remember the note id, then, you can extract the note according to the id, and the program will be complete. This also shows that your application does not need to be saved. For example, if your interface is to read a list, you do not need to remember anything special. Oh, maybe you need to remember the position of the scroll bar...
12. call and call: our communication messenger Intent
Intent is the intention. Intent communicates with each other, makes a call, and makes a call.
Intent will be sent over the phone. This is the essence of loose coupling of the Android architecture, which greatly improves the reusability of components. For example, you need to click a button in your application, it's easy to call someone. Let's look at the code first:
Java code
 
Intent intent = new Intent ();
Intent. setAction (Intent. ACTION_CALL );
Intent. setData (Uri. parse ("tel:" + number ));
StartActivity (intent );
 
Throwing out such an intention, the system will wake up the dialing program and make a call when it sees your intention. What reading contacts, text messages, emails, all just need to be thrown out of intent. This part is really well designed.
So what does Intent tell the system who needs to accept it?
There are two methods to use Intent. The first method is to directly describe which class is required to receive the Code as follows:
Java code
 
Intent intent = new Intent (this, MyActivity. class );
Intent. getExtras (). putString ("id", "1 ");
TartActivity (intent );
 
The first method is obvious. You can directly specify MyActivity as the receiver and pass some data to MyActivity. In MyActivity, you can use getIntent () to get the intent and data.
In the second method, you need to first check the intentfilter configuration in AndroidMenifest.
Xml Code
<Intent-filter>
<Action
Android: name = "android. intent. action. VIEW"
/>
<Action
Android: value = "android. intent. action. EDIT"
/>
<Action
Android: value = "android. intent. action. PICK"
/>
<Category
Android: name = "android. intent. category. DEFAULT"
/>
<Data
Android: mimeType = "vnd. android. cursor. dir/vnd. google. note"
/>
</Intent-filter>
If action, data, and category are used in the configuration, you must think that intent also has these things. Will the receiver be found after a match?
Action is actually a string name of intent.
The configuration file of intent-filter in the above section shows that this Activity can accept different actions. Of course, the corresponding program logic is different. Let's mention the mimeType, which is defined in ContentProvider, if you implement a ContentProvider by yourself, you must specify mimeType to enable data to be used by others.
I don't know the principle. I don't want to explain it. In summary, you call another interface instead of the new interface. Instead, you can throw an intent to let the system call that interface for you, in this way, it is loose and compliant with the principle that the lifecycle is managed by the system.
If you want to know what category has and what actions Android has customized for you, visit the official link Intent.
Ps: If you want to know how to call system applications, you can take a closer look at your logcat. Do you have some information when running a program? For example:
Starting activity: Intent {action = android. intent. action. MAINcategories = {android. intent. category. LAUNCHER} flags = 0x10200000comp = {com. android. camera/com. android. camera. galleryPicker }}
Compare some set methods of Intent to know how to call them. Hope you like it :)
 
 
13. How to exit the Activity? How can I safely exit the Application that has called multiple activities?
For a single Activity application, it is easy to exit. Simply finish.
Of course, you can also use methods such as killProcess () and System. exit.

However, for a Multi-Activity application, the above method is useless if you want to exit directly after opening multiple activities, this is because all the above methods end an Activity.
Of course, some people on the Internet say yes.
It's like someone asks how to capture the Home Key in the application, and someone will say that using keyCode to compare KEYCODE_HOME can be done. In fact, if you don't modify the framework, it's impossible to do this 1.1.
Therefore, you 'd better try it yourself.

Is there a way to exit the entire application directly?
You can use the restartPackage method of ActivityManager before 2.1.
It can directly end the entire application. Android. permission. RESTART_PACKAGES is required for use.
Be careful not to be confused by its name.

However, in 2.2, this method fails.
A new method named killBackgroundProcesses () is added in 2.2, and the permission android. permission. KILL_BACKGROUND_PROCESSES is required.
Unfortunately, like restartPackage 2.2, it does not have the expected effect.

Another method is to force the end of the program in the application management that comes with the system, forceStopPackage ().
It requires permission for android. permission. FORCE_STOP_PACKAGES.
Android: sharedUserId = "android. uid. system" must be added.
It is also a pity that this method is not public. It can only run in system processes and cannot be called by third-party programs.
Because LOCAL_CERTIFICATE: = platform needs to be added to Android. mk.
Android. mk is used to compile programs in the Android source code.

As can be seen from the above, in 2.2, there is no way to end an application directly, but you can only use your own method to do it indirectly.

Several methods are provided for reference:

1. Throw an exception and force Exit:
This method causes the program to Force Close by throwing an exception.
Yes, but the problem to be solved is how to end the program without the Force Close window.

2. Record the opened Activity:
Every time an Activity is opened, it is recorded. When you need to exit, close every Activity.

3. Send specific broadcasts:
Send a specific broadcast when you need to end the application. After each Activity receives the broadcast, close it.

4. Recursive exit
Use startActivityForResult when opening a new Activity, add a flag on your own, process it in onActivityResult, and disable it recursively.

Except for the first one, we try to end every Activity and achieve the goal indirectly.
However, this is not perfect.
If your application sets nosensor for each Activity, the sensor may be valid during the gap between the two activities.
But at least, our goal has been achieved without affecting user usage.

For programming convenience, it is best to define an Activity base class to deal with these common problems.
From: http://blog.csdn.net/debug2/archive/2011/02/18/6193644.aspx
14. Introduce the five la s commonly used in Android.
1. LinearLayout-linear layout.
Orientation-Arrangement of elements in a container. Vertical: vertical arrangement of child elements; horizontal: horizontal arrangement of child elements
Gravity-content arrangement. Top, bottom, left, right, center, etc.

2. AbsoluteLayout-absolute layout.
Layout_x-x coordinates. Vertex in the upper left corner
Layout_y-y coordinate. Vertex in the upper left corner

3. TableLayout-table layout
Table layout manages child controls in the form of columns. Each row is a TableRow object, and each TableRow object can be added with child controls. Each space is equivalent to adding a column.

4. RelativeLayout-relative layout.
Layout_centerInParent-place the current element in the center of the horizontal and vertical directions of the container (similar attributes include layout_centerHorizontal and layout_alignParentLeft)
Layout_marginLeft-set the distance between the current element and the left edge of its container
Layout_below-place the current element under the specified Element
Layout_alignRight-the current element is right aligned with the specified Element

5. FrameLayout-stacked layout. Starting from the upper left corner, the elements in FrameLayout are displayed layer by layer. In the frame layout, the first added image is overwritten by the last added image.
From: http://javalover00000.javaeye.com/blog/851266
15. Describe how to store Android data.
Android provides five data storage methods:
1. Use SharedPreferences to store data;
2. File storage data;
3. SQLite databases store data;
4. Use ContentProvider to store data;
5. network storage data;
Data storage in Android is private and cannot be accessed by other applications unless the data shared by other applications is obtained through ContentResolver.
From: http://www.moandroid.com /? P = 319
 
16. introduce how ContentProvider achieves data sharing.
A program can expose its data completely by implementing an abstract interface of the Content provider, and Content providers exposes data in a way similar to a table in a database. Content providers stores and retrieves data, which can be accessed by all applications. This is the only way to share data between applications. To make the data of an application public, you can create a Content provider of your own or add your data to an existing Content provider, the premise is that you have the same data type and the permission to write Content provider.

How can I obtain data exposed by other applications through a set of standard and unified interfaces? Android provides ContentResolver, and external programs can access the data provided by ContentProvider through the ContentResolver interface.
Reference: http://www.moandroid.com /? P = 319
 
17. How to enable and disable the Service.
1. The first method is to call Context. startService () to start and call Context. stopService () to end. startService () can pass parameters to the Service.

2. The second method is to call Context. bindService () to start, call Context. unbindservice () to end, and access Service through ServiceConnection.
During each Service enabling and disabling process, only onStart can be called multiple times (through multiple startService calls), other onCreate, onBind, onUnbind, onDestory can only be called once in a lifecycle.
Reference: http://www.cnblogs.com/feisky/archive/2010/06/14/1758336.html
18. There are several ways to register broadcast. What are the advantages and disadvantages of these methods? Let's talk about the intention of introducing the broadcast mechanism to Android.
In android, information transmitted between different processes needs to be broadcast, which can be implemented in two ways.
Method 1: In Manifest. registering a broadcast in xml is a recommended method because it does not need to be manually deregistered (if the broadcast is not deregistered, an error may occur when the program exits ).
The specific implementation is added to the application of Manifest:
<Explorer android: name = ". mEvtReceiver">
<Intent-filter>
<Action android: name = "android. intent. action. BOOT_COMPLETED"/>
</Intent-filter>
</Cycler>
The preceding two android: names are the broadcast name and broadcast action (the action here indicates that the system is started). If you want to send a broadcast yourself, in the Code:
Intent I = new Intent ("android. intent. action. BOOT_COMPLETED ");
SendBroadcast (I );
In this way, the broadcast is sent and then received.
You can create a new class for receiving, inherit to BroadcastReceiver, or create a BroadcastReceiver instance, and then write the onReceive method to implement it as follows:
Protected BroadcastReceiver mEvtReceiver = new BroadcastReceiver (){
@ Override
Public void onReceive (Context context, Intent intent ){
String action = intent. getAction ();
If (action. equals ("android. intent. action. BOOT_COMPLETED ")){
// Do something
}
}
};

The second method is implemented directly in the code, but you need to manually register for logout. The implementation is as follows:
IntentFilter filter = new IntentFilter ();
Filter. addAction ("android. intent. action. BOOT_COMPLETED ");
RegisterReceiver (mEvtReceiver, filter); // you have registered a recevier named mEvtReceiver, and then use the following method to override onReceiver,
Finally, you need to cancel the broadcast in onDestroy of the program. The implementation is as follows:
@ Override
Public void onDestroy (){
Super. onDestroy ();
UnregisterReceiver (mPlayerEvtReceiver );
}
 
Broadcast in Android is a widely used method for communication between applications. It is similar to the event processing mechanism, the difference is that broadcast processing is a system-level event processing process (generally, event processing is control-level ). In this process, it is still inseparable from Intent objects, understanding the handling process of broadcast events, and using the broadcast processing mechanism flexibly, which often achieves special effects at key points,
 
In Android, if you want to send a broadcast, you must use sendBroadCast to send a broadcast receiver to the system that is interested in it.
To use broadcast, you must have an intent object that must set its action object.
To use broadcast, you must explicitly specify the broadcast object in the configuration file.
Each time a broadcast is received, a new broadcast receiving object is generated.
Do not handle too many logic problems in BroadCast. It is recommended that complicated logic be handled by Activity or Service.

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.