0
다음 코드를 사용하여 오전 10시 30 분에 알람을 실행 한 다음 매 8 초마다 계속 실행하지만 문제는이 코드가 시간이 아닐 때도 알람 관리자를 실행한다는 것입니다 10:30.AlarmManager가 시간이 잘못되어 실행되었습니다.
것은
public class AlarmReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// For our recurring task, we'll just display a message
Toast.makeText(context, "Welcome Back ! ", Toast.LENGTH_SHORT).show();
}
가 나는 또한이를 추가 한 코드에 관계없이 설정 한 값 시간의 알람을 실행 유지하지만,
public class MainActivity extends Activity {
private PendingIntent pendingIntent;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/* Retrieve a PendingIntent that will perform a broadcast */
Intent alarmIntent = new Intent(MainActivity.this, AlarmReceiver.class);
pendingIntent = PendingIntent.getBroadcast(MainActivity.this, 0, alarmIntent, 0);
startAt10();
}
public void startAt10() {
AlarmManager manager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
/* Set the alarm to start at 10:30 AM */
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.set(Calendar.HOUR_OF_DAY, 10);
calendar.set(Calendar.MINUTE, 30);
/* Repeating on every 8 seconds interval */
manager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
1000 * 8, pendingIntent);
}
}
모든 노력을하고이 내 AlarmReceiver
클래스 내 AndroidManifest.xml
,
<receiver android:name="com.example.test2.AlarmReceiver" android:enabled="true" >
</receiver>
어떻게 만듭니 까? 10:30 AM에 ute?
반복 하시겠습니까, 그렇지 않으시겠습니까 **? –
매 8 초마다 반복하기를 원하지만 10시 30 분에 먼저 실행 한 다음 매 8 초마다 다시 시작해야합니다. 그러나 그것은 시간이 무엇이든 상관없이 경련을 일으키지 않으며 매 8 년마다 발화합니다. –
시간이 ** ** 10:30 이후입니까? 그러면 AlarmMAnager가 즉시 ** ** 발생합니다 (** 늦은 **이라고 생각 함). –