12

Like getIntent().getIntExtra, does getStringExtra have a default value which can be used if the string passed is empty?

I have a method to do this, but was wondering if there was an existing for achieving it to?

Thanks.

2 Answers 2

10

According to http://developer.android.com/reference/android/content/Intent.html, no.

The reason getIntExtra has a default value parameter, it is because the type returned is a primitive and therefore can't return null.

Sign up to request clarification or add additional context in comments.

Comments

6

We cannot check if it is empty, but we can check it by comparing it with null.

str = intent.getStringExtra("key");

if(str == null){
  str = "DEFAULT STRING";//Assign default string
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.