I've just noticed that, while most of getters from a Bundle
have the possibiliy of including a default value, in case the key doesn't exist in that particular bundle instance, getString
does not have that possibility, returning null if that case.
Any ideas on why is that and if there is some way of easy solution to that (by easy I mean not having to check each individual value or extending the Bundle
class).
As an example, right now you have only this:
bundle.getString("ITEM_TITLE");
While I would like to do:
bundle.getString("ITEM_TITLE","Unknown Title");
Thanks!
Trojanfoe has the best solution if that is what you want, though once you get into dealing with defaults for other datatypes you'll have to do the same thing for them all.
Another solution would be to check to see if the bundle contains the key:
String myString = bundle.containsKey("key") ? bundle.getString("key") : "default";
It's not as nice as a function, but you could always wrap it if you wanted.
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