I'm trying to use putExtra(String,String)
in my code to pass null
.
As the parameter suggests the second parameter can be null
as it is a string and I can send it
this.getIntent().putExtra(AppConstant.TestString, null);
When i use the above code it gives me error saying :
The method putExtra(String, String) is ambiguous for the type Intent
However it allows me to use :
this.getIntent().putExtra(AppConstant.TestString, "");
Kindly enlighten me on this. Thanks in advance.
When you use null
, the compiler doesn't know which is the type you want to use and cannot decide which overload of the method to use.
You can cast your null to String
to inform compiler which method you use:
this.getIntent().putExtra(AppConstant.TestString, (String)null);
Alternatively, you can create a variable and set it to null
:
String param = null;
this.getIntent().putExtra(AppConstant.TestString, param);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With