I have radio button list in alert dialog where I have to select option like alarm after 10 mints, 15 mints and n mints, But when I click on one radio button and again opening a laert dialog radio button remain un-clicked but I want selected option to be clicked. how's it is possible? Is there any need to store it's state in database or any other solution?
My Activity:
case RADIOBTN_DIALOG_ID:
AlertDialog.Builder builder2=new AlertDialog.Builder(Task_Details.this)
.setTitle("Select Reminder Time")
.setSingleChoiceItems(reminder_radio, -1, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
switch(which)
{
case 0:
AlarmReceiver alarm = new AlarmReceiver();
alarm.CancelAlarm(getApplicationContext());
alarm.OneMintAlarm(getApplicationContext());
Toast.makeText(getApplicationContext(), "Alarm", Toast.LENGTH_SHORT).show();
break;
case 1:
AlarmReceiver alarm1 = new AlarmReceiver();
alarm1.CancelAlarm(getApplicationContext());
alarm1.TenMintAlarm(getApplicationContext());
Toast.makeText(getApplicationContext(), "Alarm", Toast.LENGTH_SHORT).show();
break;
case 2:
AlarmReceiver alarm2 = new AlarmReceiver();
alarm2.CancelAlarm(getApplicationContext());
alarm2.FifteenMintAlarm(getApplicationContext());
Toast.makeText(getApplicationContext(), "Alarm", Toast.LENGTH_SHORT).show();
break;
case 3:
AlarmReceiver alarm3 = new AlarmReceiver();
alarm3.CancelAlarm(getApplicationContext());
alarm3.nMintAlarm(getApplicationContext());
Toast.makeText(getApplicationContext(), "Alarm", Toast.LENGTH_SHORT).show();
break;
}
dialog.dismiss();
}
});
BroadCastReceiver Activity:
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, " Alarm Received !!! ", Toast.LENGTH_LONG).show();
}
public void CancelAlarm(Context context)
{
Intent intent = new Intent(context, AlarmReceiver.class);
PendingIntent sender = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
alarmManager.cancel(sender);
}
public void OneMintAlarm(Context context)
{
AlarmManager alarms = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(context, AlarmReceiver.class);
PendingIntent recurringDownload = PendingIntent.getBroadcast(context,
0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
alarms.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(),
1000 * 10, recurringDownload);
}
public void TenMintAlarm(Context context)
{
AlarmManager alarms = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(context, AlarmReceiver.class);
PendingIntent recurringDownload = PendingIntent.getBroadcast(context,
0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
alarms.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(),
1000 * 600, recurringDownload);
}
public void FifteenMintAlarm(Context context)
{
AlarmManager alarms = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(context, AlarmReceiver.class);
PendingIntent recurringDownload = PendingIntent.getBroadcast(context,
0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
alarms.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(),
1000 * 900, recurringDownload);
}
public void nMintAlarm(Context context)
{
}
Please suggest what to do??? Thanks