我已经开发出remindes用户每10分钟alertDialog在2小时内申请ONLY,
I've to develop an application that remindes the user every 10 minutes with alertDialog during 2 hours ONLY,
我做了提醒用户,每次10分钟的应用程序,但我想2小时后停止它实际上我不能这样做,
I made an application that reminds a user for each 10 minutes, but I want to stop it after 2 hour actually I couldn't do that,
我搜查,但没有答案,如果我用amManger.cancel();它会2小时前取消报警:(那么,有没有办法做到这一点?并请给出一个expamle因为我是新到Android ...
I searched but no answers, if I used amManger.cancel(); it'll cancel the alarm before 2 hour :"( so, is there any way to do that ? and please give an expamle as I'm new to android...
由于alooooot ..
thanks alooooot ..
--------------更新后---------------------------
-------------- After Updating ---------------------------
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();问题: - 我应该在哪里把code停止报警时bCancel按钮自动点击?
Question: - Where should I put the code to stop the alarm when the bCancel button clicked automatically ??
- 和我怎样才能使这个点击后两小时???
-and how can I make this click after two hours ???
感谢,
推荐答案试试这个 -
final Button bCancel= (Button) findViewById(R.id.button1); bCancel.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { //Your code to stop the alarm goes here. } }); new Handler().postDelayed(new Runnable() { @Override public void run() { bCancel.performClick(); } }, (2*60*60*1000));更多推荐
如何停止报警android应用
发布评论