我有这个在固定时间执行 AlarmReceiver 的类(在 android 启动后开始)。我添加了 sharedpreferences 来禁用和启用警报。如果我禁用并重新启用警报不会运行。我需要重启模拟器。我可以避免模拟器重启吗?谢谢!
public class AutoStart extends BroadcastReceiver {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
CheckboxPreference = prefs.getBoolean("checkboxPref", true);
Calendar cal4 = Calendar.getInstance(TimeZone.getDefault(), Locale.getDefault());
cal4.set(Calendar.DATE,31);
cal4.set(Calendar.MONTH,Calendar.DECEMBER);
cal4.set(Calendar.YEAR,2012);//year...
cal4.set(Calendar.HOUR_OF_DAY, 23);
cal4.set(Calendar.MINUTE, 59);
cal4.set(Calendar.SECOND, 00);
Intent intent2 = new Intent(context, AlarmReceiver.class);
PendingIntent Alarm1 = PendingIntent.getBroadcast(context, 0, intent2, 0);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, cal4.getTimeInMillis(), DateUtils.DAY_IN_MILLIS, Alarm1);
显现:
<receiver android:name="AutoStart">
<intent-filter>
<action
android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.HOME" />
</intent-filter>
</receiver>