I'm passing an Int to a BroadcastReceiver, but I'm not sure if I'm doing correctly since sometimes it works and sometimes it doesn't.
Sending the Int:
Intent intent = new Intent(getActivity(),Broadcast_RemoveClass.class);
Bundle bundle = new Bundle();
bundle.putDouble("mInt", i);
intent.putExtras(bundle);
PendingIntent pendingIntent = PendingIntent.getBroadcast(getActivity().getApplicationContext(), 234324243, intent, 0);
AlarmManager alarmManager = (AlarmManager) getActivity().getSystemService(Context.ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 1000 * 5, pendingIntent);
Toast.makeText(getActivity(), "countdown started for: " + i,Toast.LENGTH_LONG).show();
Getting the Int:
public class Broadcast_RemoveClass extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();
int i = bundle.getInt("mInt");
Toast.makeText(context, "done" + i , Toast.LENGTH_LONG).show();
}
}
Sometimes it gets the current int but then it just comes to a point that it just keeps getting the previous passed int. When sending the intent it shows the correct int in the toast, but then it gets a wrong int in the BroadcastReceiver. Any ideas of what is making this happen?