@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Create an IntentSender that will launch our service, to be scheduled // with the alarm manager. mAlarmSender = PendingIntent.getService(AlarmService.this, 0, new Intent(AlarmService.this, AlarmService_Service.class), 0); setContentView(R.layout.alarm_service); // Watch for button clicks. Button button = (Button)findViewById(R.id.start_alarm); button.setOnClickListener(mStartAlarmListener); button = (Button)findViewById(R.id.stop_alarm); button.setOnClickListener(mStopAlarmListener); }
public void onClick(View v) { // We want the alarm to go off 30 seconds from now. long firstTime = SystemClock.elapsedRealtime(); // Schedule the alarm! AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE); am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, 30*1000, mAlarmSender); // Tell the user about what we did. Toast.makeText(AlarmService.this, R.string.repeating_scheduled, Toast.LENGTH_LONG).show(); } };
public void onClick(View v) { // And cancel the alarm. AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE); am.cancel(mAlarmSender); // Tell the user about what we did. Toast.makeText(AlarmService.this, R.string.repeating_unscheduled, Toast.LENGTH_LONG).show(); } };
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Create an IntentSender that will launch our service, to be scheduled // with the alarm manager. mAlarmSender = PendingIntent.getService(AlarmService.this, 0, new Intent(AlarmService.this, AlarmService_Service.class), 0); setContentView(R.layout.alarm_service); // Watch for button clicks. Button button = (Button)findViewById(R.id.start_alarm); button.setOnClickListener(mStartAlarmListener); button = (Button)findViewById(R.id.stop_alarm); button.setOnClickListener(mStopAlarmListener); }
public void onClick(View v) { // And cancel the alarm. AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE); am.cancel(mAlarmSender); // Tell the user about what we did. Toast.makeText(AlarmService.this, R.string.repeating_unscheduled, Toast.LENGTH_LONG).show(); } };
public void onClick(View v) { // We want the alarm to go off 30 seconds from now. long firstTime = SystemClock.elapsedRealtime(); // Schedule the alarm! AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE); am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, 30*1000, mAlarmSender); // Tell the user about what we did. Toast.makeText(AlarmService.this, R.string.repeating_scheduled, Toast.LENGTH_LONG).show(); } };