I have a class public class Alarm implements Serializable
. This has a method in it:
public void schedule(Context context) {
setAlarmActive(true);
Intent myIntent = new Intent(context, AlarmAlertBroadcastReciever.class);
Bundle bundle = new Bundle();
bundle.putSerializable("alarm", this);
myIntent.putExtras(bundle);
//myIntent.putExtra("alarm", this);
Alarm alarm = (Alarm) bundle.getSerializable("alarm");
if(alarm !=null){
Log.d("Alarmdebug", "alatm is not null");
}
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, myIntent,PendingIntent.FLAG_CANCEL_CURRENT);
AlarmManager alarmManager = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP, getAlarmTime().getTimeInMillis(), pendingIntent);
}
Elsewhere I have this code. Which is not able to get the serialized
extras. This is invoked but alarm
is always null
.
Bundle bundle = intent.getExtras();
final Alarm alarm = (Alarm) bundle.getSerializable("alarm");
if(alarm==null){
Log.d("Alarmdebug", "alarm is null 2");
}
Can you please tell me what is the issue with this code? I tried the solution here: Passing data through intent using Serializable but it doesn't work for me.
Thank you
EDIT
Anyone looking for the solution can find it below now.