高级技巧

学习目的:1.定制自己的日志工具 2.调试android程序

新建LogUitl类

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
public class LogUitl{
public static final int VERBOSE=1;
public static final int DEBUG=2;
public static final int INFO=3;
public static final int WARN=4;
public static final int VERROR=5;
public static final int NOTHING=1;
public static int level=VERBOSE;

public static void v(String tag,String msg){
if(level<=VERBOSE){
Log.v(tag,msg);
}
}
public static void d(String tag,String msg){
if(level<=DEBUG){
Log.d(tag,msg);
}
}
public static void i (String tag,String msg){
if(level<=INFO){
Log.i(tag,msg);
}
}
public static void w(String tag,String msg){
if(level<=WARN){
Log.w(tag,msg);
}
}
public static void e(String tag,String msg){
if(level<=ERROR){
Log.e(tag,msg);
}
}
}

使用 如打印WARN级别的日志

1
LogUitl.w("TAG","warn log");

2.调试android程序

3.创建定时任务 Alarm机制
如:设置一个任务10s后执行

1
2
long triggerAtTime=SystemClock.elapsedRealtime()+10*1000;
manager.set(AlarmManager.ELAPSED_REALLTIME_WAKEUP,triggerAtTime,pendingIntent);

ELAPSED_REALLTIME_WAKEUP四种模式的其中一种