目录

  • List各种
    • List
    • ArrayList
  • Map各种
    • Map vs. List
    • LinkedHashMap
    • HashMap
    • HashTable
    • Map
  • List & View
    • ExpandableList
    • RecycleView
  • Variable keyword
    • abstract
    • volatile (易挥发)
  • 多线程
    • AsyncTask
    • Thread
    • Handler
    • Timer
  • Android ViewModel

List各种

List

Just an interface.
当需要synchronized时候,使用List,如LiveData>

ArrayList

  • extends AbstractList
  • implements List, RandomAccess, Cloneable, Serializable
  • 不支持synchronized

Map各种

Map vs. List

如果已知position:map 和 list get() 操作为O(1).

LinkedHashMap

Hash table and linked list implementation of the Map interface

  • extends HashMap
  • implements Map

HashMap

  • extends AbstractMap
  • implements Map, Cloneable, Serializable
  • allow null
  • HashMap is non synchronized
  • thread Not Safe
  • Fast
  • isn’t legacy

HashTable

  • extends Dictionary
  • implements Map, Cloneable, Serializable
  • not allow null
  • Hashtable is synchronized.
  • thread Safe
  • Slow
  • It’s Legacy(old fashion)

Map

just an interface.

List & View

ExpandableList

RecycleView

Variable keyword

abstract

  • abstract class vs. abstract method
  • 如果是inner class 要用一个interface (WordDao), 如在abstract的“Room database” class, 也要把这个interface 的constructor 写成abstract。 public abstract WordDao wordDao();

volatile (易挥发)

The Java volatile keyword is used to mark a Java variable as “being stored in main memory”. Use a synchronized in that case to guarantee that the reading and writing of the variable is atomic.

Reading and writing of volatile variables causes the variable to be read or written to main memory. Reading from and writing to main memory is more expensive than accessing the CPU cache. Accessing volatile variables also prevent instruction reordering which is a normal performance enhancement technique.

only use volatile variables when you really need to enforce visibility of variables.

多线程

https://www.youtube.com/playlist?list=PLZ9NgFYEMxp50tvT8806xllaCbd31DpDy

AsyncTask

encapsulates the creation of a background process and the synchronization with the main thread. It also supports reporting progress of the running tasks.

AsyncTasks should ideally be used for short operations (a few seconds at the most.) If you need to keep threads running for long periods of time, it is highly recommended you use the various APIs provided by the java.util.concurrent package such as Executor, ThreadPoolExecutor and FutureTask.

Thread

A thread is a thread of execution in a program. The Java Virtual Machine allows an application to have multiple threads of execution running concurrently.

The Java Virtual Machine continues to execute threads until either of the following occurs:
(1) The exit method of class Runtime has been called and the security manager has permitted the exit operation to take place.
(2) All threads that are not daemon threads have died, either by returning from the call to the run method or by throwing an exception that propagates beyond the run method.

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.

There are two main uses for a Handler:
(1) to schedule messages and runnables to be executed at some point in the future;
(2) to enqueue an action to be performed on a different thread than your own.

Timer

A facility for threads to schedule tasks for future execution in a background thread. Tasks may be scheduled for one-time execution, or for repeated execution at regular intervals.

  • thread safe
  • does not offer real-time guarantees: it schedules tasks using the Object.wait(long) method.

Implementation note: This class scales to large numbers of concurrently scheduled tasks (thousands should present no problem). Internally, it uses a binary heap to represent its task queue, so the cost to schedule a task is O(log n), where n is the number of concurrently scheduled tasks.

Android ViewModel

Subclasses must have a constructor which accepts Application as the only parameter.
来自MVVM 官方 Framework
因为有生命周期,常与LiveData一起用
Activity 与 Fragment之间数据传输是友好的

更多相关文章

  1. Android生命周期
  2. Android纠正Activity横竖屏切换的生命周期的错误
  3. 从android游戏框架看其生命周期!
  4. 深入理解 Android Activity的生命周期
  5. 理解Asp.Net中WebForm的生命周期_实用技巧
  6. Asp.Net中WebForm的生命周期相关讲解
  7. Vue生命周期钩子简介[每日前端夜话0x8A]
  8. Vuex 注入 Vue 生命周期的过程
  9. 【前端词典】Vuex 注入 Vue 生命周期的过程

随机推荐

  1. android读取SDCard任意路径下的文件
  2. Android(安卓)读取XML的两种方法。
  3. Android(安卓)倒影实现算法
  4. Ubuntu 12.04 Desktop 版本编译 Android(
  5. Android(安卓)SDK无法更新终极解决方式
  6. Android(安卓)SQLite数据库解析并使用两
  7. 【Android-Third】Android三方框架相关
  8. How to generate links to the android C
  9. java.util.concurrent.ExecutionExceptio
  10. Android(安卓)8 蓝牙打开过程