BroadcastReceiver를 사용하여 알람 경고를 설정하고 있는데 어떤 이유로 작동하지 않습니다.BroadcastReceiver가 데이터를 메인 클래스로 되돌려 보내지 않음
public class SimpleSleepActivity extends Activity {
/** Called when the activity is first created. */
Button setAlarm, setTimer;
int hours = 1, alarmSec = 10;
Toast mToast;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
setAlarm = (Button) findViewById(R.id.bSetAlarm);
setTimer = (Button) findViewById(R.id.bSetTimer);
setTimer.setOnClickListener(mAlarmFromNow);
}
private OnClickListener mAlarmFromNow = new OnClickListener() {
public void onClick(View v) {
// When the alarm goes off, broadcast an Intent to the
// BroadcastReceiver. This is an Intent with an explicit class
// name to have a receiver instantiated and called, and then
// create an IntentSender to have the intent executed as a broadcast.
Intent intent = new Intent(SimpleSleepActivity.this,
AlarmFromNow.class);
PendingIntent sender = PendingIntent.getBroadcast(
SimpleSleepActivity.this, 0, intent, 0);
// Finding the current time and setting and alarm for XX seconds
// from that time
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.add(Calendar.SECOND, alarmSec);
// Scheduling the alarm
AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), sender);
if (mToast != null) {
mToast.cancel();
}
mToast = Toast.makeText(SimpleSleepActivity.this,
//Show the user what they imputed
"The alarm will go off in " + alarmSec + " Seconds", Toast.LENGTH_LONG);
mToast.show();
}
};
}
내 다른 클래스는 내가 10 초 후에 그 토스트 알림을하려고 할 때이
public class AlarmFromNow extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
//Display a toast after alarmSec is counted
Toast.makeText(context, R.string.alarm_from_now, Toast.LENGTH_LONG)
.show();
}
}
가 표시되지 않습니다이다. 나는 그것이 작동하지 않을 것이라는 다른 이유를 생각할 수 없다. 나는 구글의 API 데모를보고 밀접하게 따라 갔다.
죄송합니다. 나는 그것을 추가했다. 그러나 application> 밖에 있었다. 감사합니다 :) – domshyra