在尝试中,AsyncTask
我从服务器获取电子邮件地址。在onPostExecute()
我必须检查的是电子邮件地址empty
或null
。我使用以下代码进行检查:
if (userEmail != null && !userEmail.isEmpty()) {
Toast.makeText(getActivity(), userEmail, Toast.LENGTH_LONG).show();
UserEmailLabel.setText(userEmail);
}
但在我Toast
看来null
是印刷的。我的完整代码:
private class LoadPersonalData extends AsyncTask<String, Void, Void> {
@Override
protected void onPreExecute() {
super.onPreExecute();
}
protected Void doInBackground(String... res) {
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("user_id", PrefUserName));
params.add(new BasicNameValuePair("type", type_data));
JSONObject json = jsonParser.makeHttpRequest(Url, "POST", params);
String result = "";
try {
result = json.getString("message");
} catch (JSONException e) {
e.printStackTrace();
}
if (result.equals("success")) {
try {
userEmail = json.getString("email");
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return null;
}
@Override
protected void onPostExecute(Void result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
if (userEmail != null && !userEmail.isEmpty()) {
Toast.makeText(getActivity(), userEmail, Toast.LENGTH_LONG).show();
UserEmailLabel.setText(userEmail);
}
}
我如何检查null
和empty
串?
if (userEmail != null && (!TextUtils.equals(userEmail ,"null")) && (!TextUtils.isEmpty(userEmail))){
也有效