MyAdapter.java
public static class MyAdapter extends BaseAdapter {
private List<TimerItem> mDatas;
private Context mContext;
//用于退出 Activity,避免 Countdown,造成资源浪费。
private SparseArray<CountDownTimer> countDownCounters;
public MyAdapter(Context mContext, List<TimerItem> mDatas) {
this.mContext = mContext;
this.mDatas = mDatas;
this.countDownCounters = new SparseArray<>();
}
/**
* 清空当前 CountTimeDown 资源
*/
public void cancelAllTimers() {
if (countDownCounters == null) {
return;
}
Log.e("TAG", "size : " + countDownCounters.size());
for (int i = 0, length = countDownCounters.size(); i < length; i++) {
CountDownTimer cdt = countDownCounters.get(countDownCounters.keyAt(i));
if (cdt != null) {
cdt.cancel();
}
|