Android

安卓总览

四大组件、六大布局、五大存储

官方文档

  1. Service
  2. broadcastReceiver
  3. Activity
  4. ContentProvider

Activity的生命周期

编程范式

UI

  1. layout
  2. shape:为组件添加样式

定时器

方法: setRepeating(int type,long startTime,long intervalTime,PendingIntent pi)

type 说明
AlarmManager.ELAPSED_REALTIME 表示闹钟在手机睡眠状态下不可用,该状态下闹钟使用相对时间(相对于系统启动开始),状态值为3
AlarmManager.ELAPSED_REALTIME_WAKEUP 表示闹钟在睡眠状态下会唤醒系统并执行提示功能,该状态下闹钟也使用相对时间,状态值为2
AlarmManager.RTC 表示闹钟在睡眠状态下不可用,该状态下闹钟使用绝对时间,即当前系统时间,状态值为1;
AlarmManager.RTC_WAKEUP 表示闹钟在睡眠状态下会唤醒系统并执行提示功能,该状态下闹钟使用绝对时间,状态值为0;
AlarmManager.POWER_OFF_WAKEUP 表示闹钟在手机关机状态下也能正常进行提示功能,所以是5个状态中用的最多的状态之一,该状态下闹钟也是用绝对时间,状态值为4;不过本状态好像受SDK版本影响,某些版本并不支持;

时间以毫秒为单位

PendingIntent pi:是闹钟的执行动作,比如发送一个广播、给出提示等等。PendingIntent是Intent的封装类。

1
PendingIntent sender=PendingIntent.getBroadcast(Main.this, 0, intent, 0);

SQLlite

存储方式

主要操作:

  1. getWritableDatabase:创建 or 打开 可读/写的数据库(通过 返回的SQLiteDatabase对象 进行操作)
  2. getReadableDatabase:创建 or 打开 可读的数据库(通过 返回的SQLiteDatabase对象 进行操作)
  3. onCreate(SQLiteDatabase db): 数据库第1次创建时 则会调用.在继承SQLiteOpenHelper类的子类中复写.
  4. onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)数据库升级时自动调用.在继承SQLiteOpenHelper类的子类中复写.
  5. (Cursor) query(String table, String[] columns, String selection, String[] selectionArgs, String groupBy, String having, String orderBy, String limit): 查询
  6. (long) insert(String table,String nullColumnHack,ContentValues values)
  7. (int) update(String table, ContentValues values, String whereClause, String[] whereArgs)
  8. (int) delete(String table,String whereClause,String[] whereArgs)
  9. (void) execSQL(String sql):直接运行sql语句

坚持原创技术分享,您的支持是我前进的动力!