Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Default value for getStringExtra() if empty

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.

like image 918
fractal5 Avatar asked Sep 24 '15 23:09

fractal5


2 Answers

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
}
like image 196
GiridharaSPK Avatar answered Sep 29 '22 09:09

GiridharaSPK


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.

like image 36
tstark81 Avatar answered Sep 29 '22 10:09

tstark81