0%

前言

本文是介绍Android中的Binder机制。

目录

一、Binder是什么

Binder 是 Android 系统进程间的一种通信机制,官方介绍:

Base class for a remotable object, the core part of a lightweight remote procedure call mechanism defined by IBinder. This class is an implementation of IBinder that provides standard local implementation of such an object.

远程对象的基类,它是 IBinder 定义的轻量级远程过程调用机制的核心部分。此类是 IBinder 的实现,它提供此类本地对象的标准实现。

Read more »

前言

Handler机制是面试官非常喜欢问的知识点,本文主要是记录整理Handler相关面试题和解答。

目录

1、Handler:是什么?有什么用?为什么要用Handler,不用行不行?

Android定义的一套 线程(子线程与主线程)间通讯的消息传递机制 。把子线程中的 UI更新信息,传递给主线程(UI线程),以此完成UI更新操作。Android建议要求:我们在主线程(UI)线程中更新UI。Android的UI控件不是线程安全的,用Handler在多个线程并发更新UI的同时,保证线程的安全。

Read more »

前言

本文是介绍Android中的ThreadLocal。

目录

一、ThreadLocal是什么

ThreadLocal 是线程局部(本地)变量,也许把它命名为 ThreadLocalVariable 更容易让人理解一些。官方介绍:

This class provides thread-local variables. These variables differ from their normal counterparts in that each thread that accesses one (via its get or set method) has its own, independently initialized copy of the variable. ThreadLocal instances are typically private static fields in classes that wish to associate state with a thread (e.g., a user ID or Transaction ID).

Read more »

前言

本文是介绍Android中的IntentService。

目录

一、IntentService是什么

IntentService 是 Android 里的一个封装的抽象类,继承自 Service。官方介绍:

IntentService is a base class for Services that handle asynchronous requests (expressed as Intents) on demand. Clients send requests through Context.startService(Intent) calls; the service is started as needed, handles each Intent in turn using a worker thread, and stops itself when it runs out of work.

Read more »

前言

本文是介绍Android中的HandlerThread。

目录

一、HandlerThread是什么

HandlerThread 是 Android 已封装好的轻量级异步通信类。官方介绍:

A Thread that has a Looper. The Looper can then be used to create Handlers.

Note that just like with a regular Thread, Thread.start() must still be called.

一个具有 Looper 的线程。该 Looper 可以用来创建 Handler。和使用常规线程一样,Thread.start() 仍必须调用。

Read more »

前言

本文是介绍Android中的Handler消息机制。

目录

一、Handler消息机制是什么

Handler 机制是 Android 中用于线程间通信的一套异步通信机制。官方的介绍是:

A Handler allows you to send and process Message and Runnable objects associated with a thread’s MessageQueue. Each Handler instance is associated with a single thread and that thread’s message queue. When you create a new Handler it is bound to a Looper. It will deliver messages and runnables to that Looper’s message queue and execute them on that Looper’s thread.

Read more »

前言

本文是介绍Android常用的组件之一的Fragment。

目录

一、什么是Fragment

Fragment,简称碎片,是 Android最基本,最重要的基础概念之一。Fragment 官方的定义是:

A Fragment represents a behavior or a portion of user interface in an Activity. You can combine multiple fragments in a single activity to build a multi-pane UI and reuse a fragment in multiple activities. You can think of a fragment as a modular section of an activity, which has its own lifecycle, receives its own input events, and which you can add or remove while the activity is running.

Read more »

前言

本文是介绍Android的四大组件之一的ContentProvider。

目录

一、什么是ContentProvider

ContentProvider 是 Android 中提供的专门用于不同应用间数据交互和共享的组件。它实际上是对SQLiteOpenHelper 的进一步封装,以一个或多个表的形式将数据呈现给外部应用,通过 Uri 映射来选择需要操作数据库中的哪个表,并对表中的数据进行增删改查处理。ContentProvider 其底层使用了 Binder 来完成APP 进程之间的通信,同时使用匿名共享内存来作为共享数据的载体。ContentProvider 支持访问权限管理机制,以控制数据的访问者及访问方式,保证数据访问的安全性。

Read more »

前言

本文是介绍Android的四大组件之一的BroadcastReceiver。

目录

一、什么是BroadcastReceiver

广播是一种广泛运用的在应用程序之间传输信息的机制,BroadcastReceiver 主要用来监听系统或者应用发出的广播信息,然后根据广播信息作为相应的逻辑处理,也可以用来传输少量、频率低的数据。广播机制是一个典型的发布-订阅模式,就是观察者模式。

Read more »

前言

本文是介绍Android的四大组件之一的Service。

目录

一、什么是Service

Service 是一个应用程序组件,它能在后台执行一些耗时较长的操作,并且不提供用户界面。服务能被其他应用程序的组件启动,即使用户切换到另外的应用时还能保持后台运行。此外,应用程序组件还能与服务绑定,并与服务进行交互,甚至能进行进程间通信(IPC)。 比如,服务可以处理网络传输、音乐播放、执行文件I/O、或者与 content provider 进行交互,所有这些都是后台进行的。

Read more »