• AsyncHandler


    package com.ango.deskclock;
    
    import android.content.Context;
    import android.content.Intent;
    import android.os.Handler;
    import android.os.HandlerThread;
    
    /**
     * Helper class for managing the background thread used to perform io operations
     * and handle async broadcasts.
     */
    final class AsyncHandler {
    
        private static final HandlerThread sHandlerThread =
                new HandlerThread("AsyncHandler");
        private static final Handler sHandler;
        private static Runnable aRunnable;
    
        static {
            sHandlerThread.start();
            sHandler = new Handler(sHandlerThread.getLooper());
        }
    
        public static void post(Runnable r) {
            sHandler.post(r);
        }
        
        public static final boolean postDelayed(Context context, Alarm alarm, long delayMillis) {
        	final Context sContext = context;
        	final Alarm sAlarm = alarm;
        	aRunnable = new Runnable() {
                @Override public void run() {
                    Intent playAlarm = new Intent(Alarms.ALARM_ALERT_ACTION);
                    playAlarm.putExtra(Alarms.ALARM_INTENT_EXTRA, sAlarm);
                    sContext.startService(playAlarm);
                  }
        	};
        	return sHandler.postDelayed(aRunnable, delayMillis);
        }
        
        public static final void removeCallbacks (){
        	sHandler.removeCallbacks(aRunnable);
        }
    
        private AsyncHandler() {}
    }

            AsyncHandler.post(new Runnable() {
                @Override public void run() {
                    handleIntent(context, intent);
                    result.finish();
                    wl.release();
                }
            });
    


    //        // Play the alarm alert and vibrate the device after 10 seconds so that the user can dismiss or snooze before the alarm alert.
    //        Intent playAlarm = new Intent(Alarms.ALARM_ALERT_ACTION);
    //        playAlarm.putExtra(Alarms.ALARM_INTENT_EXTRA, alarm);
    //        context.startService(playAlarm);
            AsyncHandler.postDelayed(context, alarm, 10000); 
    

            AsyncHandler.removeCallbacks();  // remove the AsyncHandler.postDelayed(context, alarm, 10000) in AlarmReceiver.java
    






    版权声明:本文博客原创文章,博客,未经同意,不得转载。

  • 相关阅读:
    C# 之委托
    Java Maven安装及配置,利用Maven创建项目
    Java DecimalFormat四舍五入的坑及正确用法
    Java 解析XML的几种方式:DOM、SAX、JDOM和DOM4J。
    Java Properties配置文件和XML配置文件读取
    Java Map一些基本使用方法
    JAVA for循环的几种用法
    鼠标及键盘操作
    控制浏览器
    元素定位
  • 原文地址:https://www.cnblogs.com/yxwkf/p/4754439.html
Copyright © 2020-2023  润新知