誰でも私の問題を解決するのを手伝ってもらえますか、現在の時刻から 10 分後にアラームを鳴らさなければならず、10 分ごとにアラームを繰り返さなければなりません。このコードを書いたのですが、うまくいきませんでした。
public class AlarmNewActivity extends Activity {
/** Called when the activity is first created. */
Intent intent;
PendingIntent sender;
AlarmManager am;
Button bStart, bStop ;
long mCurrentTime, firstTime ;
Calendar calendar;
TextView tv;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
bStart = (Button) findViewById (R.id.button1);
bStop = (Button) findViewById (R.id.button2);
tv = (TextView) findViewById (R.id.textView1);
intent = new Intent(AlarmNewActivity.this, RepeatingAlarm.class);
sender = PendingIntent.getBroadcast(AlarmNewActivity.this, 0, intent, 0);
am = (AlarmManager)getSystemService(ALARM_SERVICE);
calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
mCurrentTime = calendar.getTimeInMillis();
bStart.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
tv.setText(""+ firstTime + "\n" + mCurrentTime );
am.setRepeating(AlarmManager.RTC_WAKEUP,
mCurrentTime + 10 *1000, 5*1000, sender);
new Handler().postDelayed(new Runnable() {
public void run() {
bStop.performClick();
}
}, ( mCurrentTime + 50 * 1000 ));
}
});
//==================================================================================
bStop.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
am.cancel(sender);
}
});
}
}