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, at which time the activity is visible to the user, but not the user's Click event When 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 during this period the system memory is low, the activity is recycled, The Ondestory () method is also called to invoke the Onresume () method when the activity resumes from the state of the dialog occlusion, which restores the clickable state when the activity is recovered from being obscured by other activity or into the background state. And when the system is not recycled, it will call Onrestart (), OnStart (), Onresume (), and revert to a state that can interact with the user when the activity is obscured by other activity or in the background, and is recycled by the system. The equivalent of reopening an activity, both calling OnCreate (), OnStart (), Onresume () method, which can interact with the user after the OnPause () method executes, the system stops the animation and other CPU-consuming operations, At the same time we should save the data here, because this time the priority of the program is reduced, it may be recalled by the system. The data stored here should be read in Onresume to help the user recover from the previous state.

After OnDestroy () execution, the activity is really killed, 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, Calling dialog's Cancel method throws an exception.

2.Intent start activity There are several ways to do it? Intent initiates activity in two ways, namely explicit intention, implicit intention first, explicit realization. [Java]View Plaincopyprint?
    1. Intent Intent = new Intent (this,otheractivity.     Class);
    2. StartActivity (Intent);

There is another form of explicit intent.

[Java]View Plaincopyprint?
    1. Intent Intent = new Intent ();
    2. ComponentName component = new ComponentName (This, otheractivity.     Class);
    3. Intent.setcomponent (component);
    4. StartActivity (Intent);

In fact, these two forms are actually the same, let's take a look at the code of the intent constructor

[Java]View Plaincopyprint?
    1. Public Intent (Context Packagecontext, class<?> CLS) {
    2. Mcomponent = New ComponentName (Packagecontext, CLS);
    3. }

So we are at a glance, in fact, we often use the intent construction method is the second way of the simplified version of the second, is the implementation of implicit intent. First, let's take a look at the implicit intent of the invocation method [Java]View Plaincopyprint?
    1. Intent Intent = new Intent ();
    2. Intent.setaction ("other");
    3. 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 [Java]View Plaincopyprint?
    1. <activity android:name="com.example.lifecicledemo.OtherActivity" >
    2. <intent-filter>
    3. <action android:name="other"/>
    4. <category android:name="Android.intent.category.DEFAULT"/>
    5. </intent-filter>
    6. </activity>

So when we use setaction, we can see which page we want to jump to. How to get a picture in 3.Android in one of several ways [Java]View Plaincopyprint?
    1. drawable drawable = Getresources (). getdrawable (R.drawable.ic_launcher);
    2. Img.setimagedrawable (drawable);

Way Two

[Java]View Plaincopyprint?
    1. Bitmap Bitmap = Bitmapfactory.decoderesource (Getresources (),
    2. R.drawable.ic_launcher);
    3. Img.setimagebitmap (bitmap);


Mode three

[Java]View Plaincopyprint?
    1. Assetmanager Assetmanager = Getresources (). Getassets ();
    2. try {
    3. InputStream is = Assetmanager.open ("ic_launcher.png");
    4. Bitmap Bitmap = Bitmapfactory.decodestream (IS);
    5. Img.setimagebitmap (bitmap);
    6. } catch (IOException e) {
    7. E.printstacktrace ();
    8. }


Mode Four

[Java]View Plaincopyprint?
    1. Assetmanager Assetmanager = Getresources (). Getassets ();
    2. try {
    3. InputStream is = Assetmanager.open ("ic_launcher.png");
    4. drawable drawable = Drawable.createfromstream (IS, null);
    5. Img.setimagedrawable (drawable);
    6. } catch (IOException e) {
    7. E.printstacktrace ();
    8. }

1. arraylist,vector, LinkedList's storage performance and features 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 direct press An ordinal index element, but the insertion element is involved in 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 performance is ArrayList poor, and LinkedList Using a doubly linked list for storage, index data by ordinal requires forward or backward traversal, but inserting the data requires only the front and back of the item to be recorded, so the insertion speed is faster. The difference between  2.collection and collections Collection is the ancestor interface of the collection class, and the main interface of the inheritance 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 Hashtable HashMap is the 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), due to non-thread-safe, may be more efficient 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's the difference between  4.sleep () and wait () sleep is a thread-class method that guidesThis thread pauses execution for the 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. The  wait is a method of the object class that calls the wait method on this 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 Override overloaded method can change the type of 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.



Android Advanced Android interview topics organized and explained

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.