2
我有一个调用AsyncTask.I的问题,我打电话给 内的AsyncTask按钮,但它不打算在后台执行和onPost执行。 点击按钮后没有任何反应。请帮我纠正 的错误。无法调用异步任务
Photo.class
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
View takephoto_view = inflater.inflate(R.layout.fragment_profile, null,false);
img_profile = (ImageView)takephoto_view.findViewById(R.id.profile_imgphoto);
but_takephoto = (Button)takephoto_view.findViewById(R.id.profile_buttakephoto);
but_savephoto = (Button)takephoto_view.findViewById(R.id.profile_butsavephoto);
but_takephoto.setOnClickListener(listener_takephoto);
but_savephoto.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
firstmethod();
}
});
return takephoto_view;
}
public void firstmethod() {
new MyAsyn(getActivity()).execute();
}
public class MyAsyn extends AsyncTask<String, String, String> {
Context con;
public MyAsyn(Context con) {
this.con = con;
}
@Override
protected String doInBackground(String... params) {
// Create a new HttpClient and Post Header
// HttpClient httpclient = new DefaultHttpClient();
//
//
// StringBuilder sb;
// try {
//
// StringEntity se = new StringEntity(json);
//
// httppost.setEntity(se);
// System.out.print(json);
// HttpResponse response = httpclient.execute(httppost);
// if(response != null)
// {
// InputStream is = response.getEntity().getContent();
//
// BufferedReader reader = new BufferedReader(new InputStreamReader(is));
// sb = new StringBuilder();
//
// String line = null;
// try {
// while ((line = reader.readLine()) != null) {
// sb.append(line + "\n");
//
// }
//
//
// } catch (IOException e)
// {
// e.printStackTrace();
// }
// finally {
// try {
// is.close();
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
//
//
//
//
// }
//
//
// }catch (ClientProtocolException e) {
// // TODO Auto-generated catch block
// } catch (IOException e) {
// // TODO Auto-generated catch block
// }
return null;
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
Toast.makeText(getActivity(), "Hello", Toast.LENGTH_LONG).show();
}
}
什么是logcat? – 2014-09-06 04:53:47
@LittleChild:没有错误显示,但过了一段时间后,它会去AsyncTask。我不知道为什么它需要一些时间来输入 – Giridharan 2014-09-06 04:55:07
如果你设置断点,会发生什么? FWIW,我从来不会在AsyncTasks中调用'super',但不应该打破它。 – 323go 2014-09-06 04:58:07