大家好,又见面了,我是全栈君,今天给大家准备了Idea注册码。
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
版权声明:本文博客原创文章,博客,未经同意,不得转载。
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/117151.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...