Android Common face question

Source: Internet
Author: User
Tags set background sqlite database

These interviews were summed up before me. Feel good, just paste it out to share with you. There are many problems. Also I have been asked by the interviewer before the question, and some other basic issues (since the basic knowledge, must be an Android developer to master).

There are a number of questions I have tried for you, so answer the interviewer. Still can ah, hey

1, the four components of Android and its role?
1. Activity:activity is a form of interaction between the user and the application, an Activity equivalent to one of our actual pages. When you open a screen, the previous screen will be set to a paused state. and pressed into the history stack, the user can return to the previously opened screen with a fallback operation. The life cycle of activity: "Generate, Run, destroy." However, there are many ways to invoke OnCreate (create), OnStart (Activate), Onresume (Restore), OnPause (pause), onStop (stop), OnDestroy (Destroy), Onrestart (reboot).
2, Service:service is a program, it can run for a very long time, equivalent to a service in the background. The StartService (Intent service) enables you to start a service by binding a service through Context.bindservice ().


3, Broadcastrecevicer: Accept one or more intent as trigger event. Accept the relevant message, do some simple processing, converted into a notification, unified the Android event broadcast model. The ability to use Broadcastreceiver to make the application respond to an external event. Broadcast receiver through Notificationmanager to inform users that these things happened, Broadcastreceiver Register of two ways, One is the ability to register in Androidmanifest.xml, and the other to use Context.registerreceiver () in code at run time.

Users can also broadcast their own intent broadcasts to other applications via Context.sendbroadcast ().


4. Content provider: It can share its own data to external call, and provide the interface of data access to third party application.

2, the optimization of the ListView program?

1, if you define the adapter, then in the GetView method to consider whether the method passed in the parameter contentview is null. Assuming null, the Contentview is created and returned. Assume that it is not NULL for direct use.

In this approach, create as few view as possible.
2, to Contentview set tag (Settag ()), passed in a Viewholder object, used to cache the data to be displayed, can achieve the image data asynchronous loading effect.
3, if the ListView needs to display a lot of item, we should consider paging loading. For example, to display 100 or many other times, we can consider loading 20 first. Wait until the user pulls to the bottom of the list and then loads the next 20 bars. Page loading has not been studied yet.

3. What are the five kinds of data storage methods in Android? What are their characteristics?

Android提供了五种存取数据的方式

(1) sharedpreference. Storage of less than five types of data, only within the same package to make
Use. The format of the generated XML is stored in the device
(2) SQLite database, storing all kinds of data, is a lightweight embedded database
(3) file files. Generate a file to store data by reading the Write method
(4) ContentProvider. Used primarily to let other applications use the saved data

(5) Get data and write data to network storage space over the network

4. List the main five regular use layouts in Android?

The most frequently used layouts are the following:
First Type: Frame layout (frame layout) framelayout
Another: Linear layout linearlayout
The third type: absolute layout absolutelayout
The fourth type: relative layout relativelayout

Fifth type: Table layout tablelayout

5. Adapter of the system provided by the narrative study? Explain the difference between your definition of adapter and system adapter?

With the Arrayadapter, Simpleadapter, and Simplecursoradapter adapters, the response to the event can only be limited to a single line unit.

Suppose there is a button control in a row, and the response action is not the same. If you are using an adapter that comes with your system. It is not possible to accurately respond to events for each control. At this point, we generally take our own definition adapter to achieve this relatively accurate request.

6. What is the difference between Asset folder and Raw folder in Android?

Res/raw and assets the same point:
The files in both folders will be stored in the APK package intact after packaging. Will not be compiled into binary.
Different points of Res/raw and assets:
(1) The files in the Res/raw are mapped to the R.java file, and when visiting, the files under the R.raw.filename;assets folder are not mapped to the R.java, and the Assetmanager class is required for access.


(2) Res/raw can not have a folder structure, and assets can have a folder structure, that is, assets folder can be re-established folder
(3) Read File Resources example:
Read the file resource under Res/raw, and get the input stream for write in the following way
InputStream is = Getresources (). Openrawresource (R.raw.filename);
Read the file resource under assets, and get the input stream for write in the following way
Assetmanager am = null;
am = Getassets ();

InputStream is = am.open ("filename");

7, explicit intent and implicit intent difference?

Intent是一种在不同组件之间传递的请求消息。是应用程序发出的请求和意图。对于明白指出了目标组件名称的Intent,我们称之为显式Intent。对于没有明白指出目标组件名称的Intent,则称之为隐式Intent。Android系统使用IntentFilter 来寻找与隐式Intent相关的对象。

An explicit intent defines the target component directly with the name of the component. This is a very straightforward approach. However, because developers often don't know the component names of other applications, explicit intent many others are used to deliver messages inside the application. For example, within an application. An activity initiates a service.
Implicit intent the opposite. It does not define the target components that need to be activated with the component name, which is more widely used to pass messages between different applications.

8. Briefly describe the steps to realize aidl?

Server side:
1:server End Write Aidl
The 2:server side inherits the service. Overriding 3 methods
The 3:server end instantiates a stub object that defines an interface Aidl and implements an abstract method of the interface;
4: Configuration file
Client
1: Copy the Aidl file
2: Binding services to service side
3: Implement Serviceconnection, in the implementation of the process through the service side passed through the IBinder to get stub objects, such as: interface name. Stub.asinterface (service);
4: Calling the corresponding method from the stub object

9, talk about service life cycle, and the difference between the two ways?

The life cycle of the *service is determined by the use of service two, with different boot modes and different life cycles.

(1) Start mode starts the service life cycle:
OnCreate ()-onstartcommond ()-ondestroy ()
There is no connection between the caller and the service, and even if the caller exits, the service is still in progress.


(2) Bind mode start service life cycle: OnCreate ()->onbind ()->–>onunbind (), OnDestroy ()
The caller and the service are bound together. The caller exits. Service even exits.

10. The adapter of the system provided by the narration (explain the difference between the definition of adapter and the system adapter)?

With the Arrayadapter, Simpleadapter, and Simplecursoradapter adapters, the response to the event can only be limited to a single line unit. Suppose there is a button control in a row, and the response action is not the same. If you use an adapter that comes with your system, you cannot accurately respond to each control's response events.

Then. We generally take our own definition of the adapter to achieve this relatively accurate request.

11, write out the ListView optimization code. It is known that its own definition in the ListView has a layout file of List_item.xml with ImageView and TextView two components with ID item_image, Item_text.

public View getView(int position, View convertView, ViewGroup parent) {  // TODO Auto-generated method stub      ViewHolder viewHolder;      if(convertView==null){          viewHolder=new ViewHolder();          convertView=LayoutInflater.from(c).inflate(R.layout.list_item, null);          viewHolder.text=(TextView) convertView.findViewById(R.id.item_text);          viewHolder.image=(ImageView) convertView.findViewById(R.id.item_image);          convertView.setTag(viewHolder);      }      viewHolder=(ViewHolder) convertView.getTag();      viewHolder.text.setText(list.get(position).getText());      viewHolder.image.setImageResource(list.get(position).getImage());      return convertView;  }  static class ViewHolder{      TextView text;      ImageView image;  }  

12. Describe the basic steps of obtaining contentprovider content through Contentresolver.

First: Get the Contentresolver class object
Contentresolver Cr=getcontentresolver ();
Second: Define the field to query string array
Third: Use Cr.query (); Returns a Cursor object
IV: Use the while loop to get the contents of the cursor

13. Describe the steps to define your contentprovider.

Define ContentProvider Steps Yourself
1) inherit Android's ContentProvider base class to implement its own ContentProvider class.


2) Implement the OnCreate method in ContentProvider, create provider data, generally for database SQLite, then we instantiate a sqliteopenhelper in OnCreate.
3) in ContentProvider rewrite insert/delete/update/query additions and deletions to change these methods. Implement the corresponding function in each method.
4) Register the ContentProvider class in the Androidmanifest.xml file. Specifies the URI for the ContentProvider.

14, how to achieve a frame animation?

Add the ImageView component to the layout file. Set background to Res/anim/fram.xml animation effect
Animationdrawable objects are obtained through the Getbackground () method of the ImageView object
Starts the frame animation by animationdrawable The object's start (). Stop () stops the animation

15, Res/raw and Assets folder difference?

Same point:

Both will remain intact in the APK package. Will not be compiled into binary code.
Different points:
1, the raw folder can only store files, can not store the next level of folders, and assets can store the next level of folders.
2. The resources under the Raw folder are mapped to R.java in the generated resource ID.

and assets won't.
3, the method of obtaining resources is different. The code is as follows:
This.getassets (). Open ("Xml/channels.xml")
This.getresources (). Openrawresource (r.raw.students)
This.getclassloader (). getResourceAsStream ("Student.xml")

16, briefly describe the principle of handler mechanism?

*andriod provides Handler and Looper to meet the communication between threads.

    Android不同意UI线程之外的线程改变UI组件的值。所以要想在其它线程里面改变UI组件的值。必须使用Handler来实现。    Looper: 一个线程能够产生一个Looper对象,由它来管理此线程里的Message Queue(消息队列)。    Handler: 你能够构造Handler对象来与Looper沟通,以便push(上传)新消息到Message Queue里;或者接收Looper从Message Queue取出的消息。

Message Queue(消息队列,特点:先进先出):用来存放线程放入的消息。 线程:UI thread 通常就是main thread,而Android启动程序时会替它建立一个Message Queue。 Handler、Looper、MessageQueue的初始化流程例如以下所看到的。

Hander持有对UI主线程消息队列UI_MQ和消息循环Looper的引用,子线程能够通过Handler将消息发送到UI线程的消息队列UI_MQ中。 Handler处理消息UI主线程通过Looper循环查询消息队列UI_MQ。当发现有消息存在时会将消息从消息队列中取出。首先分析消息,通过消息的參数推断该消息相应的Handler,然后将消息分发到指定的Handler进行处理。

17. How to use Sqliteopenhelper in Android?

1, establish a class inheritance sqliteopenhelper. Declares a construction method, including (context,name,cursorfactory,version); Create a database
2. Implement its OnCreate () CREATE table
3: Run through Onupgrade () version update;
4. Instantiate the class object, read and write to it. Run the SQL statement to create the database (when read-write is used to infer whether the database exists, assuming that it exists, does not run OnCreate, does not exist, and runs).

18, the use of sqliteopenhelper and sqlitedatabase to increase the deletion of detailed methods and parameters to check?

1, through the sqliteopenhelper to get the Sqlitedatabase object (divided into two kinds of reading and writing);
2. Call Execsql () to run the SQL statements that are changed or deleted, and to pass in the SQL statement and the required number of parameters.
Call cursor cursor = Rawquery () The statement that runs the query
3. Cursors returned for running SQL statements. to traverse;
4, close the sqlitedatabase in time.

19, the difference between SQLite and sharedpreference

(1) SQLite is an extension of the embedded SQL Database engine SQLite (sqlite embeddable sql).

SQLite is a C library that implements the embedded SQL database engine.

Programs connected with SQLite are able to use SQL database. However, there is no need to run a separate relational database management system process (separate RDBMS processes).

SQLite directly reads and writes (reads and writes directly) the database file on the hard disk.
(2) Sharedpreferences is also a kind of lightweight data storage, its essence is based on XML file storage Key-value key value pairs of data, often used to store some simple configuration information. Its storage location is under the/data/data/< package name >/shared_prefs folder. The Sharedpreferences object itself can only fetch data without supporting storage and alteration, and storage changes are implemented through the editor object.

20. Why use ContentProvider? How does it differ from SQL in implementation?

SQL can only share data within the project, and ContentProvider can share data between project.

21, descriptive narrative contentprovider what parts of the URI are composed

URI由是部分组成:

content://com.example.transportation/trains/122

A, the standard prefix: ContentProvider (content provider) scheme has been set by Android. Scheme is: content://
B, uniquely identifies the entire content Provider: hostname (or authority) used to uniquely identify this contentprovider. External callers can find it based on this identity.
C, describing the path of the data. Determine what kind of data is returned: path can be used to represent the data we want to manipulate. The path should be built according to the business
D. ID unique Callout Request data: The ID of the data we want to request

22, how to scan sdcard all multimedia files through Contentresolver?

1) Get the cursor of multimedia music by Contentresolver access system multimedia provided by ContentProvider
2) Parse cursor. Get a list of files by cursor
3) Set the ListView, display different pictures according to the format, use

23. Describe the steps to develop ContentProvider

Define ContentProvider Steps Yourself

    继承Android的ContentProvider基类实现自己的ContentProvider类。

实现 ContentProvider里的onCreate方法,创建provider的数据,一般为数据库sqlite。那么我们在onCreate里实例化一个SqliteOpenHelper。 在ContentProvider 里面重写insert/delete/update/query增删改查这些方法。

在每一个方法里面实现相应的功能。 在AndroidManifest.xml文件里注冊该ContentProvider类,为ContentProvider指定Uri。

24,. How do you access your definition ContentProvider in Android?

1: Get Contentresolver Class object: Contentresolver CR = Getcontentresolver ();
2: Defines the field string array to query.
3: Use Cr.query (URI, field array. Null. Null,null); Returns a Cursor object.


4: Use the while loop to get the contents of the cursor.

25. What are the five kinds of data storage methods in Android? What are their characteristics?

Android provides five ways to access data

(1) Sharedpreference. Store less than five types of data, can only be used within the same package, generate XML format stored in the device
(2) SQLite database, storing all kinds of data, is a lightweight embedded database
(3) file files. Generate a file to store data by reading the Write method
(4) ContentProvider, used primarily to allow other applications to use the saved data
(5) Get data and write data to network storage space over the network

26. What are the types of animations in Android? What are their characteristics and differences?

Animations in Android can be divided into two main categories: frame animation, motion tween
1) tweened Animation: (You define a start and end.) The middle part is obtained by the program operation. is to animate the objects in the scene (rotate, pan, indent, and Fade) alphaanimation (gradient animation), scaleanimation (scaled animation), Translateanimation (panning animation), Rotateanimation (rotary animation),
2) Frames-by-frame animation: Frame (a series of images for serial playback, as the effect of the film). It is the effect of animation by playing a single picture.

27,, and the two implementation of the motion tween (four can choose one to example)

1. XML configuration:

1) in the Res/anim folder, configure the corresponding tag, configure the corresponding parameters, including the initial value, animation end value. and animation time
2) loading XML animation files via Animationutils.loadanimation
3) Call the Startanimation method to turn on the animation
2, the Code implementation:

1) The object of the required tweened animation is directly new, and the corresponding parameters are passed
2) Call the Startanimation method to turn on the animation

28, how to use MediaPlayer to achieve audio playback function. What should be noticed in the development of music player?

* There are two main ways to achieve audio playback with MediaPlayer.

(Method i): Create a raw package under res and put the file in the package.

Declare in activity
A MediaPlayer object, and then the OnCreate () method
The Mediaplayer.create (context,r.raw. Resource name) method instantiates the object. and then call
The start (), Pause (), and Stop () methods of the MediaPlayer start, pause, and stop
Operation.

Finally call MediaPlayer's release () in the activity's OnDestroy ()
method to release the resource. The disadvantage of this approach is that every time you run a program, you load the resources in raw
Source files, slowing down the installation process.
(Method Two): Resources are placed in the sdcard. Declare a MediaPlayer object in the activity.
Instantiate MediaPlayer (). Use the Environment.getexternalstoragedirectory (). GetAbsolutePath () method to obtain path. Then path+=file.separator+ the resource name or package name/resource name.

Then call MediaPlayer's Setdatasource (path) to set the resource. Then call the Prepare () method first. After you call the start () method to play, call the Pause () method and the Stop () method to pause and stop the operation. Finally, the release () method is used for releasing the resources in the activity's OnDestroy ().

Note, use two o'clock, after setting the resource path, call the Prepare () method,
Use the start (), pause (), stop () method to make some inferences first, or call Qian Yao
Many times the same method easy error. Call Stop () to call the start () method before calling the prepare () method.

29. How to use the small music file Soundpool in Android?

SoundPlayer the steps to play audio:

1) New one instance; New Soundpool (4, Audiomanager.stream_music, 100); The first parameter is how many sound streams are agreed to play at the same time, the 2nd is the sound type, and the third is the quality of the sound;
2) LoadId = Soundpool.load (Context, R.raw.himi_ogg, 1);
3) Use the instance call play method to pass in the corresponding audio file ID to

30, three ways of video playback in Android?

1. The system comes with Android video playback (the simplest video player)
1) New Intent. Configuring an implicit intent
2) Get the specified file Uri via Uri.parse
3) Add URI and type to intent
4) Start Intent

2. Videoview Android provides us with a component for video playback
Videoview is a control that the Android system provides for the display and control of a media playback.
If you need a control bar, you need to add Mediacontroller

3, Surfaceview+mediaplayer
1) Build Surfaceview
2) Get Surfaceholder, set resolution
3) Add callback Interface (Surfaceholder.callback) Surfaceholder.addcallback (this) to Surfaceholder;
4) Implementation of the interface internal three methods
(surfacecreated, surfacechanged,surfacedestroyed, etc.), add display to MediaPlayer (Control Manager)
5) Add a click event to the button

31. Timer and Alertmanager

A timer is a timed operation that is performed during an application run, and the timed operation is canceled at the same time when the app exits.

Alarmmanager is a system-level timer, mainly used to activity,service,broadcastreciver the three components of the timing of the operation, when the application exits this timing operation can still proceed on time, And by using the wake-up parameters can be achieved in the system hibernation can still complete the scheduled operation.

32. How does the camera function in Android be implemented?

There are two ways to achieve the camera function:
1. Open camera through camera to take photo call system camera Run Photo:
1), first create Surfaceview
2), get Surfaceview corresponding controller, and add Surfaceview callback event (Surfaceview Create and destroy the operation separately, when Surfaceview is created, initialize camera when Surfaceview is destroyed. Releasing the camera's resources)
3), set the resolution
4), set do not maintain cache
5) Click the Takepicture incoming callback to call camera to take a picture of the instantiated Picturecallback object
2, System Photo: Start with intent, set action_image_capture,startactivity open

33, the optimization of the ListView program?

1: Infer if Contentview is null
2: Use Viewholder to cache data for one-step loading
3: Paging Loading:
1) Assume that you define the adapter. In the GetView method, consider whether the parameter passed in by the method Contentview is null. Assuming null, the Contentview is created and returned. Assume that it is not NULL for direct use.

In this approach, create as few view as possible.
2) Set tag (Settag ()) to Contentview and pass in a Viewholder object. Used to cache the data to be displayed. To achieve the effect of asynchronous loading of data.
3) Assume that the ListView needs to display a lot of item. It is necessary to consider paging loading.

For example, there are 100 or so many other times to show. We can consider loading 20 first, and then loading the next 20 when the user pulls to the bottom of the list. Page loading has not been studied yet.

34. How does MVC design model apply to Android?

1. Model: For database operation, the operation of the network should be processed in the model, the operation of the calculation of the business should be in this layer.

Can be easily understood as Java source files in Android
2. View layer: The general use of XML descriptive narrative, when used can be easily introduced, can be easily understood as an Android layout file.

Android can also be used as a view layer in javascript+html and other ways.
3. Control layer (Controller): Control the model and view coordination work. Easy to understand for Android in manifest files.

Android Common face question

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.