Android Advanced Android interview topics organized and explained

Source: Internet
Author: User

This article specializes in the study of Android interview questions, content will continue to increase with the study, if the answer is wrong, I hope you can correct me

1. Brief description of activity life cycle
when activity starts, first call OnCreate (), OnStart (), Onresume () method, at which time the activity is visible to the user.
when activity changes from visible to dialog occlusion, the OnPause () method is called, and the activity is visible to the user at this time, but cannot be app user's Click event
when the activity changes from visible to being fully covered by other activity or by clicking Home into the background, the OnPause (), OnStop () method is called in turn, and if the system memory is low during this period, Causes the activity to be recycled, the Ondestory () method is also called
the Onresume () method is called when activity resumes from a state that is blocked by dialog, which restores the state that can be clicked
Onrestart (), OnStart (), Onresume () are called in turn when activity is recovered from being obscured by other activity or in the background state, and is not reclaimed by the system. Revert to a state that can interact with the user
when activity is obscured by other activity or in the background, and is reclaimed by the system, it is equivalent to reopening an activity, calling OnCreate (), OnStart (), Onresume () method, So you can interact with the user
after the OnPause () method executes, the system stops the CPU-consuming operations such as animations, and we should save the data here, because the program's priority is reduced and may be retracted by the system. The data stored here should be read in Onresume to help the user recover from the previous state.

after the OnDestroy () is executed, the activity is really Kill, you can use isfinishing () to judge it, if there is Progress dialog show, we should cancel in the OnDestroy (), or the end of the thread, call dialog Cancel method will throw an exception.

2.Intent start activity There are several ways to do it? There are two ways to start activity intent, namely explicit intent, implicit intent the first, the explicit realization.
Intent Intent = new Intent (this,otheractivity.class);  StartActivity (Intent);  
there is another form of explicit intent.
Intent Intent = new Intent ();  ComponentName component = new ComponentName (this, otheractivity.class);  Intent.setcomponent (component);  StartActivity (Intent);  
In fact, these two forms are actually the same, let's take a look at the code of the intent constructor

Public Intent (Context Packagecontext, class<?> cls) {          mcomponent = new ComponentName (Packagecontext, CLS);  }  

So we are at a glance, in fact, we often use the intent of the construction method is the second way of the simplified versionthe second is the realization of implicit intent. first, let's take a look at the implicit intent of the invocation method
Intent Intent = new Intent () intent.setaction ("other"); StartActivity (Intent);
The implicit intent is to use the setaction to distinguish between which interface to jump to, then we definitely need to jump in the page to set a flag, we need to set this in Androidmanifest.xml
<activity android:name= "com.example.lifecicledemo.OtherActivity" >     <intent-filter>         < Action android:name= "Other"/>         <category android:name= "Android.intent.category.DEFAULT"/>     </ Intent-filter></activity>

So when we use setaction, we can see which page we want to jump to.
what are the different ways to get pictures in 3.AndroidWay One
drawable drawable = Getresources (). getdrawable (R.drawable.ic_launcher); img.setimagedrawable (Drawable);
Mode two
Bitmap Bitmap = Bitmapfactory.decoderesource (Getresources (), r.drawable.ic_launcher); Img.setimagebitmap (BITMAP);

Way Three

Assetmanager Assetmanager = Getresources (). Getassets (); try {InputStream is = Assetmanager.open ("Ic_launcher.png"); Bitmap Bitmap = Bitmapfactory.decodestream (is); Img.setimagebitmap (Bitmap);} catch (IOException e) {e.printstacktrace ();}

Mode four

Assetmanager Assetmanager = Getresources (). Getassets (); try {InputStream is = Assetmanager.open ("ic_launcher.png");D Rawable drawable = Drawable.createfromstream (is, null); img.setimagedrawable (drawable);} catch (IOException e) {e.printstacktrace ();}

1. Arraylist,vector, LinkedList storage performance and featuresboth ArrayList and vectors use arrays to store data, which is larger than the actual stored data in order to add and insert elements, both of which allow the element to be indexed directly by ordinal, but the insertion element involves memory operations such as array element movement. So the index data is fast and the insertion data is slow, Vector due to the use of the Synchroni Zed method (thread safety), usually the performance of the ArrayList poor, and LinkedList using a doubly linked list for storage, index data by ordinal need forward or back traversal, However, when inserting data, you only need to record the item's front and rear items, so the insertion speed is faster.
the difference between 2.Collection and collectionsCollection is the ancestor interface of the collection class, and the main interface for inheriting it is set and List. Collections is a helper class for a collection class that provides a series of static methods for searching, sorting, threading, and so on for various collections.
the difference between 3.HashMap and HashtableHashMap is a lightweight implementation of Hashtable (non-thread-safe implementation), they all complete the Map interface, the main difference is that the HASHMAP allows null (NULL) key value (key), because of non-thread security, efficiency may be higher than Hashtable. HASHMAP allows NULL to be used as a entry key or value, and Hashtable is not allowed. HashMap Hashtable contains method removed, changed to Containsvalue and ContainsKey. Because the contains method is easy to cause misunderstanding. Hashtable inherits from the Dictionary class, and HashMap is an implementation of the Map interface introduced by Java1.2. The biggest difference is that the Hashtable method is Synchronize, and HashMap is not, when multiple threads access Hashtable, they do not need to synchronize their methods, and HASHMAP must provide external synchronization. The Hash/rehash algorithms used by Hashtable and HashMap are probably the same, so there is no big difference in performance.
What is the difference between 4.sleep () and wait ()Sleep is a threading class (thread) method that causes this thread to pause execution for a specified time, giving the execution opportunity to other threads, but the monitoring state remains and is automatically restored when it is finished.  Calling sleep does not release the object lock. Wait is a method of the object class that calls the wait method on this object to cause the thread to discard the object lock, to wait for the lock pool to wait for the object, and only to emit the Notify method for this object (or Notifyall) After this thread enters the object lock pool is ready to get an object lock into the running state.
the difference between 5.Overload and OverrideCan the Overloaded method change the type of the return value? The overridden overriding and overloaded overloading of a method are different manifestations of Java polymorphism. Overriding overriding is a representation of polymorphism between a parent class and a subclass, and overloading overloading is a representation of polymorphism in a class. If you define a method in a subclass that has the same name and arguments as its parent class, we say that the method is overridden (overriding). When an object of a subclass uses this method, the definition in the subclass is called, and for it the definition in the parent class is "masked". If more than one method with the same name is defined in a class, they either have a different number of arguments or have different parameter types, which is called a method overload (overloading). The Overloaded method is to change the type of the return value.
6. What are the similarities and differences between synchronous and asynchronous, and under what circumstances are they used separately? if the data will be shared between threads. For example, the data being written may be read by another thread later, or the data being read may have been written by another thread, then the data is shared and must be accessed synchronously. When an application calls a method that takes a long time to execute on an object and does not want the program to wait for the method to be returned, it should use asynchronous programming, which is often more efficient in many cases with asynchronous approaches.


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.