I am doing some support work on an app that a previous placement student developed which is an app that takes in user input say 5. This then means that an alarm will sound every 5 minutes.
Her app has came back to me as the alarm has a mind of its own and has been inconsistent. Here is the code that she is using:
alertDialogBuilder = new AlertDialog.Builder(MainActivity.this);
//set alert
alertDialogBuilder
.setTitle("IP Check frequency: " + time.getText() + " minutes")
.setMessage("Processing commenced at \n" + startTime.getText())
.setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (currentTime.after(alarmTime)) {
Toast.makeText(MainActivity.this, "Missed first alert", Toast.LENGTH_LONG).show();
}
intent1 = new Intent(MainActivity.this, MyBroadcastReceiver.class);
i = Integer.parseInt(time.getText().toString());
scTime2 = (i * 60 * 1000); //5 minutes before set time
pendingIntent = PendingIntent.getBroadcast(MainActivity.this, 0, intent1, PendingIntent.FLAG_UPDATE_CURRENT);
manager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
manager.setRepeating(AlarmManager.RTC_WAKEUP, timeCommenced, scTime2, pendingIntent);
Toast.makeText(MainActivity.this, "Alert Set", Toast.LENGTH_SHORT).show();
stopped.setVisibility(View.VISIBLE);
commenced1.setVisibility(View.GONE);
//Change editText to TextView
time.setVisibility(View.GONE);
timeText.setVisibility(View.VISIBLE);
timeText.setText(time.getText().toString());
processingText.setText(R.string.processing_commenced);
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
alertDialog = alertDialogBuilder.create();
alertDialog.show();
}
}
I can see that she is using SetRepeating()
and I have read that from api level 19 plus this may be the problem.
I have tried using SetExact()
but I am getting a red line under the variables inside the method.
Would anyone be able to tell me how I can keep the variables but get the consistency?
Thanks!