首先,请查看下面的代码。
我的AsyncTask代码:
public class loadNewMeeting extends AsyncTask<String, String, String> {
int intCount = 0;
JSONObject jnewmeeting;
JSONArray attendants;
public String doInBackground(String... args) {
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("attendant[userid]", Userid));
jnewmeeting = jParser.makeHttpRequest(str_url_att, "POST", params);
try {
int success = jnewmeeting.getInt("msg");
if (success == 1) {
attendants = jnewmeeting.getJSONArray("attendant");
for (int i = 0; i < attendants.length(); i++) {
JSONObject c = attendants.getJSONObject(i);
int intRole = c.getInt("role");
if (intRole == 3 ){
intCount = intCount +1;
}
}
}
} catch (JSONException e) {
e.printStackTrace();
}
return String.valueOf(intCount);
}
protected void onPostExecute(String file_url) {
countMeeting = String.valueOf(intCount);
SetCount(countMeeting);
if (intMeetingNum < intCount)
Toast.makeText(getBaseContext(), "You get " + (intCount - intMeetingNum) + " new meeting(s)", Toast.LENGTH_LONG).show();
intMeetingNum = intCount;
}
}
我无法从AsyncTask外部获取countMeeting
。我尝试制作Set and Get方法,但countMeeting
仍然为null。寻求帮助。
感谢。
答案 0 :(得分:0)
为什么不从“doInBackground”方法返回countMeeting?
由于你没有使用“file_url”返回值,在“onPostExecute”方法中,只需更改“doInBackground”方法的返回值,“doInBackground”方法的签名,“onPostxecute”的签名“和AsyncTask初始化的第三个参数。