Some trivial Android summary (1)

Android related


Briefly describe the overall architecture of Android

Android adopts a layered structure, from high to low are "application layer", "application framework layer", "core class library", "linux kernel"

Android 5.0 new features

Material Design
supports multiple devices
New notification center design Support for
64-bit ART virtual machine
Battery life improvement plan




What's New in Android 6.0

Software rights management
Web experience improvement
app association
Android payment
Fingerprint support
Power management

Activity life cycle

Activity startup method

explicit start

Intent  intent = new Intent(this,OtherActivity.class);
startActivity(intent);

implicit start

Activity startup mode

1. Standard mode
(create a new instance at the top of the stack every time an Activity is started)
2. singleTop mode
(every time an Activity is started, it will check whether the instance exists at the top of the stack, and if not, create a new instance)
3. singleTask mode
(to ensure that the entire Activity has only one instance in the application, when the Activity is started, if the instance exists, it will be reused, and all other Activities above the Activity will be popped off the stack, if not, a new instance will be created)
4 . singleInstance mode
(there is only one instance in this mode, and this instance will only exist independently in a task stack)

How to exit safely after multiple activities have been called

  1. throw exception force quit
  2. Record open activities and exit one by one
  3. Send a specific broadcast for safe exit
  4. Exit each Activity recursively

How many ways to start a Service

  1. Call startService()
    to start a service started in this way will exist in the background for a long time, even if the component that started it should be destroyed, the service is still running. The service may be killed when memory is low. When the resources are sufficient, the service will be restarted again.
    [onCreate()->onStartCommand()->startService()->onDestroy()]

2. Call bindService() to start
BindService and use the bindService() method to bind the service. The caller and the binder are bound together. Once the caller exits the service, it will be terminated [onCreate()->onBind()->onUnbind ()->onDestroy()].

## Types of broadcasts
1. Unordered broadcast (cannot be intercepted)
2. Ordered broadcast (can be intercepted using abortBroadcast())

How to register broadcast receivers

  1. Static registration Register
    in AndroidManifest.xml, it will be registered in the system once run, and the application will also receive broadcast after running out of order.
  2. Dynamic
    registration Instead of registering components in AndroidManifest.xml, directly call registerReceiver() of Context to register dynamically. The broadcast receiver takes effect only when the code runs. When the code runs, the broadcast receiver will also be invalidated.

Understanding of ContentProvider

Content providers are one of the four major components of Android. It can be used to realize the function of data sharing between different applications, and at the same time, it can ensure the security of data. ContentProvider is to use the form of tables to organize data. No matter what data comes over, it will be treated as a table, and then the data will be manipulated by adding, deleting, modifying and checking. Each ContentProvider has a public URL, which is used to represent the data provided by this ContentProvider.
When an external application wants to add, delete, modify, and query the data in the ContentProvider, it needs to use the ContentResolver to complete it.
This object is created by Context.getContextResolver().

ContextProvider/ContextResolver/ContextObsever三者

  1. ContextProvider exposes the application's private data (such as databases) to other applications so that they can access these private data. At the same time, it provides a method of adding, deleting, modifying and checking. If you let other applications access, you need to expose a public URL.
  2. ContextResolver performs CRUD operations based on URLs
  3. ContextObsever When the data in the ContextProvider changes, the callback method is executed.

Understanding Fragment

Fragment (fragment) must be hosted in Activity, it can be seen as a modular area, but it also has its own life cycle.
The loading methods are static loading and dynamic loading.
Static loading: Put the Fragment directly into the interface as a normal UI control
Dynamic loading: You need to understand the Fragment transaction first. A transaction is an atomic/unsplittable operation.
Process: 1. Open a transaction -> perform Fragment operations through the transaction -> submit the transaction, if it fails, the addition is unsuccessful.

Features of Http Protocol

Http (Hypertext Transfer Protocol) is a request/response protocol. After the client establishes a connection with the server, the client sends a request to the server, and vice versa, the server returns a response to the client.
1. Simple and fast When the
client makes a request to the server, it only needs to send the request method and path
2. Flexible
Allows the transmission of any type of data, using Content-Type to mark
3. Stateless The
protocol has no memory ability for transaction processing, if subsequent processing requires The previous data needs to be retransmitted

Animation in Android

  1. Tween Animation
  2. Frame Animation
  3. Property Animation

Android common video playback methods

  1. Use the built-in player
  2. Use VideoView
  3. Play with MediaPlayer and SurfaceView

Briefly describe the understanding of the Handler operating mechanism

It receives messages from other threads and informs the main thread through the message to update the content of the main thread.
Message: information passed in the thread
MessageQueue: message collection, used to store Runnable and Message
Looper: keep looping the message queue, as long as Take it out when there is news

Understanding of AsyncTask asynchronous tasks

AsyncTask specializes in asynchronous problems, mainly to open up a new thread for time-consuming operations
(not familiar enough)

How to draw View

  1. Measure View size
  2. Determine View Position
  3. Draw View

Understanding of AIDL

Optimization of ListView control

  1. Reuse convertView
  2. Define the storage control reference class ViewHolder
  3. Batch and paginated loading of data
  4. image processing

1. Try to avoid using static in BaseAdapter to define global variables
2. Avoid using threads in ListView adapter

How to handle OOM exceptions generated by network images

  1. resize image ·
  2. Instantly recycle unused image resources
  3. cache image in memory

RxJava

RxAndroid

How to do screen adaptation

  1. Set picture adaptation
  2. 9patch adaptation
  3. Layout adaptation

Some understanding of the Android life cycle

  1. For onStart and onStop, it is called from whether the Activity is visible , and OnResume and onPause are called from whether the Activity is in the foreground .

FlexboxLayout

Common properties:
1. flexDirection main axis item arrangement direction
2. flexWrap supports line wrapping
3. justifyContent defines the alignment of items on the main axis
4. alignItems defines the alignment of items on the secondary axis (single line works)
5. alignContent defines Alignment of multiple axes (multiple lines work)
Attributes of child elements:
1. layout_order By default, the arrangement of child elements is sorted according to the order of the document flow, and orderattributes can control the order of arrangement, negative values ​​come first, positive values is behind.

Android library

  1. Butter Knife
  2. EventBus (Android Event Publish/Subscribe Framework) Traditional event delivery methods include: Handler, BroadcastReceiver, and interface callbacks

EventBus

Simplifies communication between application components and between components and background threads. For example, when the network is requested, the UI is notified through Handler or Broadcast when the network returns, and the two Fragments need to communicate through Listener.

ButterKnife

Advantages:
1. Powerful viewbinding, clickevent and other processing functions, simplify the code
2. The runtime will not affect the efficiency of the APP, easy to use and
configure

ButterKnife through APTcompile-time parsing technology

ScrollView

When ScrollViewthe content is larger than its own size, ScrollViewa scroll bar will be added automatically and it can slide vertically.
[ScrollView][1]

ImageView


  1. ScaleType setting Define android:scaleType=”center|centerCrop|centerInside|fitCenter|fitXY|”
    in layout.xml [ScaleType setting in ImageView][2]

    What is the difference between sendEmptyMessage() and sendMessage() in Android Handler?

    sendMessage() allows you to process Message objects (Messages can contain data, ).
    sendEmptyMessage() can only put data.
    Note : a msg of message type, a what of int type, and what is passed will eventually be converted to msg
    [please see here][3]

    Talking about MVPinAndroid

    View : Corresponding to Activity, responsible for View drawing and interaction with users
    Model : Business logic and entity model
    Presenter : Responsible for completing the interaction between View and Model

    Custom View

    Process
    Start –> constructor (View initialization) –> onMeasure() (measure view size) –> onSizeChanged() (determine view size) –> onLayout() (determine subview layout (used when including subviews))
    –> onDraw()

    Toast packaging skills

    public class ToastUtil{
    private static Toast toast;
    public static void showToast(Context context,String content){
        if(toast == null){
            toast = Toast.makeText(context,content,Toast.LENGTH_SHORT);
        }else{
            toast.setText(content);
        }
        toast.show();
    }
    }

    How to choose three SdkVersion in Android studio

complileSdkVersion
1. Tell gradle which Android SDK to use to compile your application.
2. Therefore we strongly recommend to always compile with the latest SDK . There are many benefits to using new compilation checks on existing code, avoiding newly deprecated APIs, and being prepared for new APIs.

minSdkVersion
1. minSdkVersion is the minimum requirement for the app to run
2. Remember that libraries you use, such as Support Library or Google Play services, may have their own minSdkVersion. The minSdkVersion set by your application must be greater than or equal to the minSdkVersion of these libraries. For example, there are three libraries, their minSdkVersion is 4, 7 and 9 respectively, then your minSdkVersion must be at least 9 to use them. In the few cases where you still want to use a library with a higher minSdkVersion than your app (to handle all edge cases, make sure it's only used on newer platforms), you can use the tools:overrideLibrary flag, but do it thoroughly test!

targetSdkVersion
1. targetSdkVersion is the main basis for Android to provide forward compatibility

Rxjava2.0 in Android

Principle: Based on an extended observer mode
Role table display:

Role effect analogy
Observable generate event customer
Observer Receive events and give response actions kitchen
Subscribe Connect Observed & Observer waiter
Event Observed & Observer Communication Carrier dishes

Permission Management in Android

  1. For example to request camera permission (android 5.0 and above)
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {   //sdk>=5.0 请求照相机权限
            if (checkSelfPermission(Manifest.permission.CAMERA)
                    != PackageManager.PERMISSION_GRANTED) {
                requestPermissions(new String[]{Manifest.permission.CAMERA},
                        REQUEST_PERMISSION_CAMERA);
            }
        }

Add a horizontal line in Android

<View

        android:layout_width="fill_parent"
        android:layout_marginTop="10dp"
        android:layout_height="1dp"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:background="#aa000000" />

ViewPager

Disable color on both sides of ViewPager

Set android:overScrollMode=”never” in the layout

Viewpager's sliding listener OnPagerChangeListener

    /** 
     * 滑动监听器OnPageChangeListener 
     *  OnPageChangeListener这个接口需要实现三个方法:onPageScrollStateChanged,onPageScrolled ,onPageSelected 
     *      1、onPageScrollStateChanged(int arg0) 此方法是在状态改变的时候调用。 
     *          其中arg0这个参数有三种状态(0,1,2) 
     *              arg0 ==1的时表示正在滑动,arg0==2的时表示滑动完毕了,arg0==0的时表示什么都没做 
     *              当页面开始滑动的时候,三种状态的变化顺序为1-->2-->0 
     *      2、onPageScrolled(int arg0,float arg1,int arg2) 当页面在滑动的时候会调用此方法,在滑动被停止之前,此方法回一直被调用。 
     *          其中三个参数的含义分别为: 
     *              arg0 :当前页面,及你点击滑动的页面 
     *              arg1:当前页面偏移的百分比 
     *              arg2:当前页面偏移的像素位置  
     *      3、onPageSelected(int arg0) 此方法是页面跳转完后被调用,arg0是你当前选中的页面的Position(位置编号) 
     */  

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324519244&siteId=291194637