码迷,mamicode.com
首页 > 其他好文 > 详细

DateTimeChangedReceiver

时间:2020-06-16 14:43:54      阅读:50      评论:0      收藏:0      [点我收藏+]

标签:ant   intent   cti   time   gis   tap   receiver   get   vat   

package com.android.demo.lileidemo.listener;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Handler;

import com.android.demo.lileidemo.MyApplication;
import com.android.demo.lileidemo.constant.AppConstants;

/**
* date: 04/22/2020.
* author: lilei.
*/
public class DateTimeChangedReceiver extends BroadcastReceiver {
private static final String TAG = AppConstants.APP_TAG + "DateTimeChangedReceiver ";
private Handler mWorker;
private static volatile DateTimeChangedReceiver mInstance;

public DateTimeChangedReceiver() {
mWorker = new Handler();
}

/**
* get Instance.
*
* @return instance.
*/
public static DateTimeChangedReceiver getInstance() {
if (mInstance == null) {
synchronized (DateTimeChangedReceiver.class) {
if (mInstance == null) {
mInstance = new DateTimeChangedReceiver();
}
}
}
return mInstance;
}

public void registerIviStateChangeListener() {
//LogUtil.d(TAG + "registerIviStateChangeListener()");
registerReceiver();
}

/**
* registerReceiver.
*/
private void registerReceiver() {
//LogUtil.d(TAG + "registerReceiver private");
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(Intent.ACTION_TIME_CHANGED);
intentFilter.addAction(Intent.ACTION_DATE_CHANGED);
MyApplication.getAppContext().registerReceiver(DateTimeChangedReceiver.getInstance(),
intentFilter);
}

@Override
public void onReceive(Context context, Intent intent) {
if (intent != null && (Intent.ACTION_TIME_CHANGED.equals(intent.getAction())
|| Intent.ACTION_DATE_CHANGED.equals(intent.getAction()))) {
//LogUtil.d(TAG + "onReceive:" + intent.getAction());
doDateTimeChange();
}
}

private void doDateTimeChange() {
//when data time change should reInit timer.
//call reInitTimer();
}
}

DateTimeChangedReceiver

标签:ant   intent   cti   time   gis   tap   receiver   get   vat   

原文地址:https://www.cnblogs.com/adamli/p/13140575.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!