1、放到assets文件夹里的图片路径是什么?
file:///android_asset/
2、Timer 和 CountDownTimer 如果在activity里直接new的话,在时间没走完的情况下退出activity,会导致内存泄露。但是如果把countdowntimer写到一个单例类里面,暴露出start和stop方法的话,就不会报内存泄露。
private static final String TAG = "cj";
static ScreenOffCountDown instance;
public static ScreenOffCountDown getInstance() {
if (instance == null) {
synchronized (ScreenOffCountDown.class) {
if (instance == null) {
instance = new ScreenOffCountDown();
}
}
}
return instance;
}
private CountDownTimer timer = new CountDownTimer(20 * 1000, 1000) {
@Override
public void onTick(long millisUntilFinished) {
// Log.e(TAG, "onTick: " + millisUntilFinished);
Log.e(TAG, "onTick: " + millisUntilFinished + " 线程名称是:" + Thread.currentThread().getName());
}
@Override
public void onFinish() {
Log.e(TAG, "onFinish: 灭屏");
Intent intent = new Intent("haha");
MyApplication.getInstance().sendBroadcast(intent);
}
};
// public void start(){
// timer.start();
// }
public void stop() {
timer.cancel();
}
public void reStart() {
timer.cancel();
timer.start();
}
}
网友评论