Android face question Summary strengthening re-enhancement edition (i)

Source: Internet
Author: User
Tags message queue sqlite database


On the basis of the enhanced version of the Android application surface to strengthen the question set some slightly bloated, only for learning
1.activity life cycle.

Method

Describe

Can be killed

Next

OnCreate ()

Called when the activity is created for the first time. Here is where you do all the initialization settings-create views, set layouts, bind data to lists, and more. If there was ever a status record (see Saving Activity state as described later.) ), this method is called to pass in a package object that contains the previous state of the activity as a parameter.

Always followed by OnStart ().

Whether

OnStart ()

Onrestart ()

OnStop () After activity stops and is called before it is started again.

Always followed by OnStart ().

Whether

OnStart ()

OnStart ()

Called when the activity is about to become visible to the user.

When activity shifts to the foreground, Onresume () is followed by OnStop () when activity becomes hidden.

Whether

Onresume ()
Or
OnStop ()

Onresume ()

Called before the activity begins to interact with the user. The activity is at the top of the stack and accepts user input.

followed by OnPause ().

Whether

OnPause ()

OnPause ()

Called when the system will start another activity. This method is mainly used to persist unsaved changes and stop the CPU-like actions such as animations. This should be done in a short period of time, because the next activity must wait until this method returns before continuing.

When activity returns to the foreground is followed by Onresume (). OnStop () Occurs when activity becomes invisible to the user.

Is

Onresume ()
Or
OnStop ()

OnStop ()

This method is called when activity is no longer visible to the user. This can happen if it is destroyed or another activity (possibly existing or new) returns to the running state and overwrites it.

If activity returns to the foreground and the user interacts with Onrestart (), the activity is followed by OnDestroy ().

Is

Onrestart ()
Or
OnDestroy ()

OnDestroy ()

Called before the activity is destroyed. This is the last call the activity receives. This can happen at the end of the activity (calling its finish () method) or temporarily destroying an instance of this acitivity because the system requires space. You can use the Isfinishing () method to differentiate between these two situations.

Is

Nothing

Added

1. OnCreate (): Called when activity is created (first time). Action: Set layout file, initialize view, bind data file, etc.


2, OnStart (): When the activity can be seen by us.


3, Onresume (): When the activity to obtain the user's focus, is to be able to be manipulated by the user.


4, OnPause () [Pause pause meaning]:activity pause. When the application launches another activity. Example: A call came in and the system started the phone activity. What is to be done in this function is to save the activity data, and when the phone is answered, the data is read out and the original activity is restored.


5. OnStop (): When the second activity completely blocks the first activity. The dialog box does not completely obscure the original activity and will not be called.


6, OnDestroy (): Destroy activity. 1) called the Finish () method. 2) system resources are not enough.


Function Call Procedure:

When you start your first activity:

The first time you create a oncreate ()-->activity It is visible that onstart ()-->activity can manipulate Onresume ().

Click the button on the first activity to jump to the second activity via intent:

The first activity pauses OnPause () and creates a second activityoncreate ()-->activity visible onstart ()-->activity operable onresume () and The first activity is completely obscured by the second activity (OnStop) (if a finish () is called, or if the system resource is scarce, it will be destroyed ondestory ()).


Click on the system return function to build, from the second activity to the first activity:

The second activity pauses OnPause () and the first activity restarts Onrestart () (and is not destroyed if you destroy it to create OnCreate ())-The first activity is visible onstart ()- The first activity operable onresume () and the second activity is completely obscured by onstop () (If you call Finish (), or if the system resource is scarce, it will be destroyed ondestory ()).


2. The life cycle of the activity when switching between the screen and the

1. When the activity's android:configchanges is not set, the screen will recall each life cycle, and will be executed once when the screen is cut and two times when the vertical screen is cut.

2. When you set the activity's android:configchanges= "orientation", the screen will recall the life cycle, and it will only be executed once when the screen is cut horizontally or vertically.

3. When you set the activity's android:configchanges= "Orientation|keyboardhidden", the screen does not recall the individual lifecycles, only the Onconfigurationchanged method is executed.

What are the types of animations in 3.android, and what are their characteristics and differences?

Android offers two mechanisms for creating simple animations: tweened animation (motion tween) and frame-by-frame animation (frame animation).

    • tweened Animation: Animate objects by constantly making image transformations (panning, zooming, rotating) in the scene
    • Frame-by-frame Animation: Sequential playback of pre-done images, similar to movies

Both of these animation types can be used in any view object to provide a simple rotation timer, activity icons, and other useful UI elements. tweened Animation is operated by the andorid.view.animation bag; frame-by-frame Animation is operated by the Android.graphics.drawable.AnimationDrawable class.

To learn more about creating tweened and Frame-by-frame animations, read the discussion in the relevant section of the Dev guide-graphics-2d Graphics.

The Animation is defined in XML format, and the XML file that is defined is stored in the Res/anim. As the definition and use of tween animation and frame-by-frame animation are very different, we will introduce separately, this space mainly introduces the definition and use of tween animation. Follow the structure of the XML document "parent node, child node, properties" to introduce tween Animation, which consists of 4 types:

    • Alpha: Gradient Transparency Animation effect
    • Scale: Gradient dimension stretch animation effect
    • Translate: Move animation effect on picture transition position
    • Rotate: Picture conversion angle Moving animation effect

Before introducing the above 4 types, the Tween animation common node attribute is introduced.

Table I.

properties [Type] Function
Duration[long] property is animation duration The time is measured in milliseconds
Fillafter [Boolean] When set to True, the animation conversion is applied after the animation is finished
Fillbefore[boolean] When set to True, the animation conversion is applied before the animation starts

Interpolator

Specifies the insertion of an animation There are some common inserts
Accelerate_decelerate_interpolator
Acceleration-deceleration animation insertion device
Accelerate_interpolator
Acceleration-Animation insertion Device
Decelerate_interpolator
Deceleration-Animation insertion device
Other animations that belong to a specific animation effect
Repeatcount[int] Number of repetitions of an animation
Repeatmode[int] Define repetitive behavior 1: Re-start 2:plays backward
Startoffset[long] The interval between animations, starting with how much time the last animation stopped to perform the next animation
Zadjustment[int] Defines the change of the z order of the animation 0: Keep Z order unchanged
1: Stay on top
-1: Stay on the lowest level

Let's start with a concrete example of each of the 4 types of node elements that are unique to each other.

Table II

XML node Function description
Alpha Gradient Transparency Animation effect
<alpha
Android:fromalpha= "0.1″
Android:toalpha= "1.0″
Android:duration= "3000″/>
Fromalpha

property is the transparency at the beginning of the animation

0.0 means completely opaque
1.0 indicates full transparency
The above values take a number of float data types between 0.0-1.0
Toalpha property is the transparency at the end of the animation

Table III

Scale Gradient Dimension Stretch animation effect
<scale
Android:interpolator= "@android: Anim/accelerate_decelerate_interpolator"
Android:fromxscale= "0.0″
Android:toxscale= "1.4″
Android:fromyscale= "0.0″
Android:toyscale= "1.4″
android:pivotx= "50%"
Android:pivoty= "50%"
Android:fillafter= "false"
Android:startoffset= "700"
Android:duration= "700″
Android:repeatcount= "10″/>
Fromxscale[float] Fromyscale[float] The scaling dimensions on the X and y coordinates when the animation starts 0.0 means shrink to No
1.0 indicates normal no scaling
Values less than 1.0 indicate shrinkage
Values greater than 1.0 indicate magnification
Toxscale [float]
Toyscale[float]
When the animation ends, the scaling dimensions on the X and y coordinates
Pivotx[float]
Pivoty[float]
The start position of the x and Y coordinates of the animation relative to the object Property value Description: From 0%-100%, 50% is the midpoint position on the x or Y coordinate of the object

table four

translate picture conversion position Move animation effect
<translate
Android:fromxdelta= "30″
Android:toxdelta=" -80″
Android: Fromydelta= "30″
android:toydelta=" 300″
android:duration= "2000″/>
fromxdelta
Toxdelta
&NBSP;
fromydelta
Toydelta
&NBSP;
&NBSP; &NBSP; &NBSP;

Table V

Rotate Picture Transfer rotation animation effect
<rotate
Android:interpolator= "@android: Anim/accelerate_decelerate_interpolator"
Android:fromdegrees= "0″
Android:todegrees= "+350″
android:pivotx= "50%"
Android:pivoty= "50%"
Android:duration= "3000″/>
Fromdegrees The angle of the object at the beginning of the animation Description
When the angle is negative--indicates counterclockwise rotation
When the angle is positive--Indicates clockwise rotation
(Negative from--to positive: clockwise rotation)
(Negative from--to negative: counterclockwise rotation)
(Positive from--to positive: clockwise rotation)
(Positive from--to negative: counterclockwise rotation)
Todegrees

Object rotation at the end of the animation can be more than 360 degrees in angle


Pivotx
Pivoty
The start position of the x and Y coordinates of the animation relative to the object Note: The above two attribute values are taken from the 0%-100% value
50% is the midpoint position on the x or Y coordinate of the object

The Android SDK provides the base class: Animation, which contains a number of set/getxxxx () functions to set up, read Animation properties, which are the various properties shown in the previous table. Tween animation is made up of 4 types: alpha, scale, translate, roate, and the corresponding class is provided in the Android SDK, and the animation class derives alphaanimation, Scaleanimation, Translateanimation, and rotateanimation respectively implement animations that change alpha values, scaling, panning, and rotation, each of which adds its own unique properties based on the parent class.

Added

There are two kinds of animation effects on Android, one is tweened animation (tween animation) and the second is frame by frame animation. We usually use the first kind. tweened animations are also divided into alphaanimation, transparency conversion rotateanimation, rotation transformation scaleanimation, zoom conversion translateanimation position translation (move).
The animation effect is defined in an XML file in the Anim directory, loaded into a animation object with Animationutils.loadanimation (Context context,int resourcesid) in the program, When the animation effect needs to be displayed, perform the Startanimation method of the view that requires animation, and pass in the animation. Toggle activity can also apply animation effect, after the StartActivity method, the execution of the Overridependingtransition method, two parameters are the animation effect before switching, the animated effect after switching

4. What is the maximum number of bytes in a text message?

Chinese 70 (including punctuation), English 160 bytes.

Principles of the 5.handler mechanism

Andriod provides Handler and Looper to meet the communication between threads. Handler first-out principle. The Looper class is used to manage the exchange of messages (message exchange) between objects within a particular thread.

1) Looper: A thread can produce a Looper object that manages this line thread message queue.

2) Handler: You can construct a Handler object to communicate with Looper in order to push a new message into the message queue, or to receive a message sent by Looper out of the message queue.

3) Message queue (Message Queuing): Used to hold messages placed by the thread.

4) Thread: The UI thread is usually the main thread, and the Android launcher will create a message Queue for it.

6. What is embedded real-time operating system and is the Android operating system part of the RTOs?


Embedded real-time operating system refers to when the external events or data generated, can be accepted and fast enough to be processed, the results of the processing can be within the specified time to control the production process or to respond quickly to the processing system, and control all real-time tasks coordinated operation of the embedded operating system. Mainly used in industrial control, military equipment, aerospace and other areas of the system response time has stringent requirements, which requires the use of real-time systems. Can be divided into soft real-time and hard real-time two kinds, and Android is based on the Linux kernel, and therefore belongs to soft real-time

7.android thread and threads, how processes communicate with processes

1. When an Android program starts running, it will start a process separately.
By default, all activity or service in this program will run in this process.
By default, an Android program has only one process, but a process can have a number of thread.
2. When an Android program starts running, there is a main thread that is created. This thread is primarily responsible for the display, update, and control interaction of the UI interface, so it is also called the UI thread.
When an Android program was created, a process presented a single-threaded model-that is, the main thread, and all the tasks were run in one thread. Therefore, each function called by the Main thread should be as short as possible. For more time-consuming work, you should try to give the sub-thread to do so as to avoid blocking the main thread (the main thread is blocked, causing the program to feign animation).

3. Android single-threaded model: Android UI operations are not thread-safe and must be executed in the UI thread. If you modify the UI directly in a child thread, the exception is caused.

8.Android DVM processes and Linux processes, whether the application process is the same concept

DVM refers to DALIVK virtual machines. Each Android application runs in its own process and has a separate instance of the Dalvik virtual machine. And each DVM is a process in Linux, so it can be thought of as the same concept.

What is the role of the EF file for 9.sim cards

SIM card file system has its own specifications, mainly in order to communicate with the mobile phone, SIM itself can have its own operating system, EF is for storage and communication with the mobile

11. Turn activity into a window: Activity property settings

Talk about something easy, maybe someone wants to make the app is a floating in the main interface of mobile phone things, then very simple you just need to set up the activity of the topic can be defined in the androidmanifest.xml where the activity in a word:

XML code

1. Android:theme= "@android: Style/theme.dialog"

This causes your application to pop up as a dialog box, or

XML code

1. Android:theme= "@android: Style/theme.translucent"

It becomes translucent, [friendly tip-.-] similar to the properties of this activity can be on Android. As seen in the Androidmanifestactivity method of the R.styleable class, the properties of all elements in Androidmanifest.xml can be referenced in this class android.r.styleable

It says the attribute name, what the value is on Android. As you can see in R.style, this "@android: Style/theme.dialog" corresponds to Android. R.style.theme_dialog, (' _ ' replaced with '. ' <--NOTE: This is the article content is not a smiley face) can be used in the description file, find the class definition and description of the corresponding relationship in the file is understood.

12. How do I publish the SQLite database (dictionary.db file) with the apk file?

Answer: You can copy the Dictionary.db file to the Res raw directory in Eclipse Android project. All files in the Res raw directory are not compressed so that the files in that directory can be extracted directly. The dictionary.db file can be copied to the Res raw directory

13. How do I open a database file in the Res AW directory?

Answer: You cannot open a database file in the Res raw directory directly in Android, but you need to copy the file to a directory in your phone's memory or SD card when the program first starts, and then open the database file. The basic method of replication is to use the Getresources (). Openrawresource method to obtain the InputStream object of a resource in the Res raw directory, and then write the data in the InputStream object to the corresponding file in the other directory. The Sqlitedatabase.openorcreatedatabase method can be used in the Android SDK to open SQLite database files in any directory.

14. The specific embodiment of MVC in Android

Android's official recommended application is developed using MVC mode. What is MVC? Look first.

MVC is an acronym for Model,view,controller, and you can see that MVC contains three parts:

.. Model object: Is the main part of the application, and all business logic should be written in the

Layer.

.. View object: Is the part of the application that is responsible for generating the user interface. Also in the whole

The only layer the user can see in the MVC schema, receiving input from the user and displaying processing results.

.. Controller object: Control user interface data display and update according to user's input

The part of the Model object state, the controller is more important a navigation function, in response to the user's departure phase

To the M-layer processing.

Android encourages weak coupling and component reuse, and the specific embodiment of MVC in Android is as follows

1) View layer: The general use of XML file interface description, the use of the time can be very convenient to introduce, of course, how you know more about Android, you can probably think of Android can also use javascript+ HTML and so on as the view layer, of course, there is a need for the communication between Java and JavaScript, fortunately, Android provides a very convenient communication between them implementation.

2) control layer (Controller): The task of Android control layer usually falls on the shoulders of many acitvity, this sentence also implies do not write code in the acitivity, to the model layer through activity to do business logic processing, Another reason for this is that the response time of Acitivity in Android is 5s, and if time-consuming operations are put here, the program is easily recycled.

3) Model: the operation of the database, the operation of the network, etc. should be processed in the model, of course, business calculations and other operations must be placed in the layer.

Architecture of the 15.Android system

Android's system architecture, like its operating system, employs a layered architecture. From the architecture diagram, Android is divided into four tiers, from the high-level to the lower layer, which are application layer, application framework layer, system run-level and Linux core.

1. Application

Android is published with a range of core application packages, including email clients, SMS short message programs, calendars, maps, browsers, contact management programs, and more. All applications are written in the Java language.

2. Application Framework

Developers also have full access to the API framework used by the core application. The architectural design of the application simplifies the reuse of components, and any application can publish its block of functionality and any other application can use its published block of functionality (subject to the security restrictions of the framework). Similarly, the application reuse mechanism also makes it easy for users to replace program components.

Hidden behind each app is a series of services and systems, including;

* Rich and extensible view (views) that can be used to build applications, which include lists (lists), grids (grids), text boxes (texts boxes), buttons (buttons), and even web browsers that can be embedded.

* Content Providers allows applications to access data from another application, such as a contact database, or share their own data

* Resource Manager (Resource Manager) provides access to non-code resources such as local strings, graphics, and layout files.

* Notification Manager (Notification Manager) enables applications to display customized prompts in the status bar.

* Activity Manager is used to manage the application lifecycle and provide common navigation fallback functionality.

For more details and how to write an application from scratch, refer to how to write an Android app.

3. System Runtime Library

1) Program Library

Android contains a number of C + + libraries that can be used by different components of the Android system. They provide services to developers through the Android application framework. Here are some core libraries:

* System C Library-a standard C system function library (LIBC) inherited from BSD, which is specifically tailored for embedded Linux-based devices.

* Media Library-based on PacketVideo Opencore; The library supports a variety of commonly used audio, video format playback and recording, while supporting still image files. Encoding formats include MPEG4, H. MP3, AAC, AMR, JPG, PNG.

* Surface Manager-manages the display subsystem and provides seamless integration of 2D and 3D layers for multiple applications.

* Libwebcore-an up-to-date web browser engine with support for Android browser and an embeddable Web view.

* SGL-The underlying 2D graphics engine

* 3D Libraries-based on OpenGL ES 1.0 APIs, the library can use hardware 3D acceleration (if available) or use highly optimized 3D soft acceleration.

* FreeType-Bitmap (bitmap) and vector (vectors) font display.

* SQLite-A lightweight relational database engine that is available and powerful for all applications.

2) Android Runtime

Android includes a core library that provides most of the functionality of the Java programming language core library.

Each Android application runs in its own process and has a separate instance of the Dalvik virtual machine. Dalvik is designed as a device that can run multiple virtual systems at the same time and efficiently. Dalvik Virtual Machine Execution (. dex) Dalvik executable, which is optimized for small memory usage. While the virtual machine is a register-based, all classes are compiled by the Java compiler and then converted to. dex format by the "DX" tool in the SDK to be executed by the virtual machine.

Dalvik virtual machines rely on some of the features of the Linux kernel, such as threading mechanisms and underlying memory management mechanisms.

4.Linux kernel

Android's core system services rely on the Linux 2.6 kernel, such as security, memory management, process management, network protocol stacks, and drive models. The Linux kernel also acts as an abstraction layer between the hardware and the software stack.

Added





http://blog.csdn.net/spy19881201/article/details/5775484

Android face question Summary strengthening re-enhancement edition (i)

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.