2014-04-28 165 views
0

我想设置一个报警,在几分钟内重复编辑文本,但它似乎只是当它想要工作。编辑文本设置重复报警

public void startAlert(View view) { 
     EditText text = (EditText) findViewById(R.id.time); 
     int i = Integer.parseInt(text.getText().toString()); 
     try { 
     Intent myIntent = new Intent(this, NotifyService.class); 
     AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); 
     pendingintrent = PendingIntent.getService(this.getApplicationContext(), 
       12345, myIntent, 0); 
     alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime(), 
       i * 60 * 60 , pendingintrent); 
     } catch (Exception e) {} 

     Toast.makeText(this, "Alarm set in " + i + " minutes", 
       Toast.LENGTH_LONG).show(); 
     finish(); 
    } 
} 

回答

0

setRepeating()方法的时间间隔值是在毫秒的格式。所以你需要改变你的setRepeating()方法的线如下,

alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime(), 
     i * 60 * 60 * 1000, pendingintrent);