So the porblem is that I am trying to make a notification for my app and can not find why do I get null all the time! Here is what I do:
Intent intent = new Intent(context, NotificationReceiver.class);
intent.putExtra("object", object);
intent.putExtra("year", year);
Toast.makeText(context, object.getName() + " setUpNotification", Toast.LENGTH_SHORT).show();
And I am recieving a Toast "objectName(whatever it is) setUpNotification"
But when I want to recieve that intent, here is what happens:
@Override
public void onReceive(Context context, Intent intent) {
if(intent!=null){
myObject object = intent.getParcelableExtra("object");
int year = intent.getIntExtra("year", 0);
if(object !=null){
Toast.makeText(context, "in onReceive object != null", Toast.LENGTH_LONG).show();
}else if(year!=0){
Toast.makeText(context, "in onReceive object == null but year is: " + year, Toast.LENGTH_LONG).show();
}else{
Toast.makeText(context, "in onReceive object task==null and year==0", Toast.LENGTH_LONG).show();
}
}
}
I am recieving that sequence of Toasts:
- objectName(whatever it is) setUpNotification
- in onReceive both object==null and year==0
But if I delete only this line of code "intent.putExtra("object", object);" than I will recieve that sequence of Toasts:
- objectName(whatever it is) setUpNotification
- in onReceive object==null but year is: 2023
WHY is that? I have no idea! P.S. I had never had any problems with Parcelable before that, between any activity or enywhere else everything worked perfectly. The problems with Parcelable appears ONLY here.
I have read: Parcelable object that receives passed data coming up null Passing parcelable object to new activity returns null Why is the parcelable object null in receiving activity? Android Parcelable -- RetailerOrderActivity.java return null and a lot more!
But that didn't help.