アラームマネージャを使用して、ある分後に仕事をしました。しかし、私はその活動を開くたびに残りの時間を見つける必要があります。それを行う方法は?残り時間の取得方法は?
Intent myIntent = new Intent(Activity1.this, Activity2.class);
pendingIntent = PendingIntent.getService(Timeractivity.this, 0, myIntent, 0);
int time = Integer.parseInt(time_et.getText().toString());
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.add(Calendar.MINUTE, time);
alarmManager.set(AlarmManager.RTC_WAKEUP,calendar.getTimeInMillis(),pendingIntent);
Toast.makeText(Timeractivity.this, "You set an timer of " + time + " minutes", Toast.LENGTH_LONG).show();
は、イベントが(例えば、午前14時00分)に予定された時間を取得し、現在の時刻(例えば13時20分)を引く:
は、ここに私の完全な答えを確認してください。結果として0:20を取得する必要があります。 – DBX12
サンプルコードをお願いします! – suman
回答に記載されている例を使用することをお勧めします。コンパイル時に実例を提供していないので、私はそれを書きました。 – DBX12