我开始为Android Studio的应用程序执行同步。我的代码是:异步任务和敬酒 - Android
private class Check_Loguin_Request extends AsyncTask<String,Void,String>{
@Override
protected String doInBackground(String... strings) {
//Declaration of variables
String User = strings[0];
String Pass = strings[1];
DefaultHttpClient httpClient;
HttpPost Request = new HttpPost(url_Loguin);
HttpResponse Response;
HttpParams httpParameters = new BasicHttpParams();
// Set the timeout in milliseconds until a connection is established.
// The default value is zero, that means the timeout is not used.
int timeoutConnection = 3000;
HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection);
// Set the default socket timeout (SO_TIMEOUT)
// in milliseconds which is the timeout for waiting for data.
int timeoutSocket = 5000;
HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
httpClient = new DefaultHttpClient(httpParameters);
List<NameValuePair> BodyRequest_Elements = new ArrayList<NameValuePair>();
BodyRequest_Elements.add(new BasicNameValuePair("user_name", User));
BodyRequest_Elements.add(new BasicNameValuePair("user_passwd", Pass));
try {
HttpEntity entity = new UrlEncodedFormEntity(BodyRequest_Elements);
Request.setHeader(entity.getContentType());
Request.setEntity(entity);
Response = httpClient.execute(Request);
HttpEntity entity2 = Response.getEntity();
InputStream is = entity2.getContent();
return Response.toString();
}
catch (Exception ex){
Log.getStackTraceString(ex);
return null;
}
}
protected void onPostExecute(String result){
Toast.makeText(this, "Task Finalized: " + result, Toast.LENGTH_SHORT).show();
}
}
这个类是一个外部类我的主要活动(Sync_Class)(Loguin_Activity),当我把这个在敬酒IDE给我的错误。那我怎么能从我的活动中发送上下文?提前致谢,并对我的英语感到抱歉!
PD1:如果您需要更多的代码或信息,请给我建议! :d
Check_Loguin_Request类是否在Loguin_Activity中? – 2014-11-20 18:41:03