1

我使用警报管理器每 30 秒调用一次 Web 服务。我在登录应用程序时注册它。但它每 3 秒被调用一次。此外,在其他活动中,我正在取消它,但它也没有被取消。

注册码:

Intent intent = new Intent(this, MyBroadcastReceiver.class); 
intent.putExtra("usrid", getIntent().getStringExtra("usrid")); 
PendingIntent pendingIntent =PendingIntent.getBroadcast(this.getApplicationContext(), 234324243, intent, 0); 
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime()+2000, 30*1000, pendingIntent); 
Toast.makeText(this, "Alarm set in 10 seconds", Toast.LENGTH_LONG).show();

为了取消它,代码是:

Intent intent = new Intent(this, MyBroadcastReceiver.class);
intent.putExtra("usrid", getIntent().getStringExtra("usrid"));
PendingIntent pendingIntent = PendingIntent.getBroadcast(this.getApplicationContext(), 234324243, intent,0);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
alarmManager.cancel(pendingIntent);

问题是什么。请帮忙。提前谢谢。

4

0 回答 0