ItemEdit Activity
에서 내 앱에 알람을 생성합니다. 하나는 메모/할 일 항목을 편집/볼 수있는 곳이며, 거기에 항목에 대한 미리 알림/알람을 설정할 수도 있습니다. 또한 나는 내 매니페스트에 다음과 같은 한 : 나는 다음과 같은 코드를 사용하여 알람 설정 :알람은 내가 설정 한 활동에있을 때만 발생합니다.
private void createAlarm() {
Intent intent = new Intent(this, ReminderReceiver.class);
intent.putExtra("reminder_message", "Reminder Received!");
intent.putExtra("item_id", mRowId);
PendingIntent sender =
PendingIntent.getBroadcast(
getApplicationContext(),
ALARM_ID,
intent,
PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT);
// Get the AlarmManager service
AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
// Set alarm to the time given by the user.
am.set(AlarmManager.RTC_WAKEUP, mReminderCal.getTimeInMillis(), sender);
}
을 그리고 여기에 수신기
public class ReminderReceiver extends BroadcastReceiver {
private static final String TAG = "MyApp";
@Override
public void onReceive(Context context, Intent intent) {
try {
Bundle bundle = intent.getExtras();
String message = bundle.getString("reminder_message");
Log.v(TAG, message);
} catch(Exception e) {
Log.v(TAG, "OH SNAP!");
e.printStackTrace();
}
}
편집은
<receiver android:process=":remote" android:name="ReminderReceiver"></receiver>
만약 I Activity
에 머물러서 알람이 울리면 괜찮습니다. 모든 항목이 나열되거나 앱을 완전히 종료 한 상태 인 ListActivity
으로 돌아 가기 위해 뒤로 버튼을 누르면 알람이 트리거되지 않습니다. 내가 그것을 설정 한 활동에서 방아쇠를 당긴다는 경보를 설정하는 데 잘못된 것이 있었습니까?
감사합니다.
나는 그것을 고려하고 있었다. 아마 나는 Alarm의 흐름이 어떻게 작동하는지 오해하고있다. 그러나'AlarmManager'는 OS가 넓고 현재'Activity'가 현재 활성화되어 있는지 여부에 관계없이 시작될 것이라고 생각했다. 나는이 가정에서 잘못 될 수있다. –
@Jonathon. 당신은 정확했습니다. 나는 '서비스'로 일하게 만들었습니다. 당신은 대답을 만들어서 당신에게 신용을 줄 수 있습니까? –
추가 - 당신은 답변을 입력하고 난 정말 당신에게 그다지 도움이되지 않았기 때문에 자신의 것을 선택할 수 있습니다 :) –