java check if bundle has property

java check if bundle has property

To check if a Bundle object has a property in Java, you can use the containsKey method of the Bundle class. This method takes a key as an argument and returns a boolean value indicating whether the bundle contains an entry with the specified key.

Here's an example of how to use the containsKey method to check if a Bundle object has a property:

re‮t ref‬o:lautturi.com
Bundle bundle = new Bundle();
bundle.putString("key", "value");

if (bundle.containsKey("key")) {
  // bundle has a property with the key "key"
} else {
  // bundle does not have a property with the key "key"
}

In this example, the if statement will evaluate to true because the bundle contains an entry with the key "key".

You can also use the containsKey method to check if a Bundle object has a property of any type. For example:

Bundle bundle = new Bundle();
bundle.putInt("key", 123);

if (bundle.containsKey("key")) {
  // bundle has a property with the key "key"
} else {
  // bundle does not have a property with the key "key"
}

In this example, the if statement will again evaluate to true because the bundle contains an entry with the key "key".

Note that the containsKey method only checks for the presence of a key in the bundle, and not the value associated with key.

Created Time:2017-11-03 00:14:48  Author:lautturi