Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/194.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
调用需要API级别12(当前最小值为9):android.os.Bundle#getString_Android - Fatal编程技术网

调用需要API级别12(当前最小值为9):android.os.Bundle#getString

调用需要API级别12(当前最小值为9):android.os.Bundle#getString,android,Android,对于小于12的API,如何使以下工作正常进行 sourceId=getIntent().getExtras().getString(“sourceId”、“defaultKey”) 您可以使用API 1中添加的 public String getString (String key) 返回与给定键关联的值,如果给定键不存在所需类型的映射,或null值与该键显式关联,则返回null。 参数 输入一个字符串或null 返回 字符串值,或null 它没有默认值,但您可以手动检查它是否为null so

对于小于12的API,如何使以下工作正常进行

sourceId=getIntent().getExtras().getString(“sourceId”、“defaultKey”)

您可以使用API 1中添加的

public String getString (String key)
返回与给定键关联的值,如果给定键不存在所需类型的映射,或null值与该键显式关联,则返回null。
参数
输入一个字符串或null
返回
字符串值,或null

它没有默认值,但您可以手动检查它是否为
null

sourceId = getIntent().getExtras().getString("sourceId");
if (sourceId == null)
    sourceId = "defaultKey";
试试这个

sourceId = getIntent().getExtras().getString("sourceId");
if(TextUtils.isEmpty(sourceId)){
   sourceId = "defaultKey";
}else{

}
TextUtils文档

sourceId = getIntent().getExtras().getString("sourceId");
if(TextUtils.isEmpty(sourceId)){
   sourceId = "defaultKey";
}else{

}