【发布时间】:2012-03-15 18:59:35
【问题描述】:
我必须开发一个应用程序,在 2 小时内每 10 分钟使用 alertDialog 提醒用户,
我做了一个应用程序,每 10 分钟提醒一个用户,但我想在 2 小时后停止它实际上我做不到,
如果我使用 amManger.cancel(); 我搜索但没有答案它会在 2 小时前取消闹钟 :"( 那么,有没有办法做到这一点? 请举个例子,因为我是 android 新手...
谢谢alooooot ..
------------- 更新后----------------------------
public class MyAlarm extends Activity {
private PendingIntent pendingIntent;
int i = 1;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button buttonStart = (Button) findViewById(R.id.startalarm);
Button buttonCancel = (Button) findViewById(R.id.cancelalarm);
Button bCancel= (Button) findViewById(R.id.button1);
pendingIntent = PendingIntent.getService(MyAlarm.this, 0,
new Intent(MyAlarm.this, MyAlarmService.class), 0);
buttonStart.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
long firstTime = SystemClock.elapsedRealtime();
AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
AlarmManager am2 = (AlarmManager) getSystemService(ALARM_SERVICE);
am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
firstTime + 10 * 1000, 10 * 1000, pendingIntent);
}
});
bCancel.performClick();
问题: - 当 bCancel 按钮自动单击时,我应该在哪里设置停止警报的代码?
-我怎样才能在两个小时后进行此点击???
谢谢,
【问题讨论】: