Android Interview Review

Source: Internet
Author: User

1. Life cycle of activity

2. Service life cycle

3. Service and activity on the same thread?

By default, it is in the same main thread. However, you can configure different processes by using the android:process property in the manifest.

4. What is soft reference in Java?

If an object has only soft references, enough memory space is available, the garbage collector does not recycle it, and if the memory space is insufficient, the memory of those objects is reclaimed. The object can be used by the program as long as it is not reclaimed by the garbage collector. Soft references can be used to implement memory-sensitive caches.

A soft reference can be used in conjunction with a reference queue (Referencequeue), and if the object referenced by the soft reference is reclaimed by the garbage collector, the Java Virtual machine will add the soft reference to the reference queue associated with it.

5, internal class mechanism

First, the definition

The class that is placed inside a class is called the inner class.

Second, the role

1). Internal classes can be very good to implement the hidden

The generic non-intrinsic class is not allowed to have private and protected permissions, but the inner class can

2). Inner class has access to all elements of the perimeter class

3). But to achieve multiple inheritance

4). You can avoid modifying the interface and implementing the invocation of two methods of the same name in the same class

6. Describe encapsulation, abstraction, inheritance, and polymorphism in Java

Package : In object-oriented languages, encapsulation features are represented by classes, and we define a class of real-life entities as classes, including properties and behaviors (which are methods in Java), as if humans could have name,sex,age properties, as well as Eat (), sleep (), etc. Behavior, we realize certain function in the behavior, also can manipulate the attribute, this is object-oriented encapsulation characteristic;
abstract : Abstraction is the abstraction of the common attributes of a class of entities encapsulated in an abstract class, so abstraction is represented by abstract classes in object-oriented languages. For example, a bird is an abstract entity, because an abstract entity is not a real object, and its properties cannot fully describe an object, so it can not be instantiated in the language as abstract class;
inheritance : inheritance is like a father-child relationship in our real life, the son can inherit some of the characteristics of fathers, in object-oriented language, is a class can be inherited from another class of some characteristics, so that code can be reused, in fact, the inheritance embodies the is-a relationship, the parent class subclass in essence or a class of entities;
Polymorphic : Polymorphism is the ability to refer to different subclass objects by passing them to the parent class to show different behavior, polymorphism can provide better extensibility for the program, and it can also be reused by code.

7,private, protected, default, public

1, private modifier, that the members are private, only their own can access;

2, protected, represents the protected permission, embodied in inheritance, that is, subclasses can access the parent class protected members, while other classes within the same package can also access the protected members.

3, no modifier words (default), indicating the package access rights (friendly, the Java language is not friendly this modifier, so that the name should be derived from C + +), the same package can be accessed, access is the package level access rights;

4, public modifier, that the member is open, all other classes can be accessed;

8, say your understanding of the service

Service is one of the four components for handling long-time operations without the need to interact with users or to provide functionality to interact with other applications.

9, the four components have been used, a simple introduction of their use

Activity :

In an application, an activity is usually a separate screen that shows some controls that can also listen and handle the user's events to respond.

Broadcastreceiver broadcast Receivers :

Applications can use it to filter external events only to receive and respond to an external event of interest, such as when the phone is being called, or when the data network is available. The broadcast receiver does not have a user interface. However, they can start an activity or serice to respond to the information they receive, or use Notificationmanager to notify the user. Notifications can be used in a variety of ways to attract users ' attention-flashing back lights, shaking, playing sounds, and more. In general, a persistent icon is placed on the status bar, and the user can open it and get the message.

Service Services :

A service is a long life cycle, without a user-interface program that can be used to develop programs such as monitoring classes.

Content Provider contents Provider :

The Android platform provides content provider to make the specified data set for an application available to other applications. This data can be stored in a file system, in a SQLite database, or in any other reasonable manner. Other applications can obtain or deposit data from the content provider through the Contentresolver class (see contentprovideraccessapp example). (equivalent to outsourcing a shell in an application), a content provider is required only if the data needs to be shared among multiple applications. For example, Address book data is used by multiple applications and must be stored in a content provider.

Its benefits: Unified access to data.

The difference between 10,UDP and TCP

UDP: 1, the full address information is given in each datagram, so there is no need to establish a connection between the sender and the receiver.

2 , UDP transmission of data is limited by size, each transmitted datagram must be limited to 64KB.

3,UDP is an unreliable protocol in which datagrams sent by the sender do not necessarily reach the receiver in the same order

tcp : 1, the connection-oriented protocol, the connection must be established before data transfer between sockets, so the connection in TCP is required < EM id= "__mcedel" > time.   < EM id= "__mcedel" >         

2,TCP transmission Data size limit, once the connection is established, the sockets of both sides can be transmitted in a uniform format of large  data.

3,TCP is a reliable protocol that ensures that the receiver is fully and correctly getting all the data sent by the sender.

11, in which case the C code needs to be called in the Java code

1, when the program is sensitive to time or performance requirements are particularly high, it is necessary to use the lower language

2. When there is already a ready-made function in other languages, it needs to be called directly from Java

3, when you need to use the Java standard platform does not have to rely on the characteristics of the operating system

12, introduce the task in Android

Task, simply put, is a collection of activity components that are clustered together in a stack of patterns. They have potential pre-and post-drive associations, the newly added activity component, at the top of the stack, and only activity at the top of the stack, before they have the opportunity to interact with the user. When the activity at the top of the stack completes its mission, the task will pull it out and let the next activity that will run to the top of the stack come to the user, until no more activity,task ends in the stack.

13,activity Start-up mode  

Activity startup mode settings:

<activity android:name=". Mainactivity "android:launchmode=" Standard" />

Four startup modes of activity:

1. Standard

mode startup mode, activity is created each time the activity is activated and placed in the task stack.

2. Singletop

If there is an instance of the activity at the top of the task, reusing the instance will create a new instance and put it in the top of the stack (even if the activity instance already exists on the stack, as long as it is not on top of the stack, an instance will be created).

3. Singletask

If an instance of the activity is already in the stack, the instance is reused (Onnewintent () of the instance is invoked). When reused, the instance is returned to the top of the stack, so the instances above it will be removed from the stack. If the instance does not exist in the stack, a new instance is created to be put into the stack.

4. SingleInstance

Create the activity instance in a new stack and have multiple apps share the activity instance in this stack. Once an instance of the activity of the pattern exists on a stack, any application that activates the activity will reuse the instance in that stack, which would have the effect of sharing an app with multiple applications, regardless of who activates the activity and enters the same one.

What are the characteristics of the final defined class in 15,java

Cannot be inherited

- . Can I play toast in the service?

you can.      

Handler handler=New  Handler (Looper.getmainlooper ());          Handler.post (new  Runnable () {              publicvoid  run () {                  "Hello android! " , Toast.length_long). Show ();              }          });

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.