我正在尝试在同一个片段中执行两个AsyncTask但是当我运行我的应用程序时,我的手机冻结并仍然加载我的代码 当我执行一个asynTask时,每件事都没问题
这是尝试执行的地方
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
Log.w(LOG_TAG,"onActivityCreated------------");
// First AsyncTask execution called
new RecomenddedChaneel().execute();
//Second AsyncTask execution called
new Loadchannels().execute();
//this is the first asyncTask method
public class RecomenddedChaneel extends AsyncTask<String, Void, List<Video>> {
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(getActivity());
pDialog.setMessage("Loading channel list. Please wait...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();
}
@Override
protected List<Video> doInBackground(String... urls) {
channelForCategory= new ArrayList<Video>();
channelForCategory.clear();
// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("uky", uk));
params.add(new BasicNameValuePair("per_page","10"));
JSONObject json = JsonFromHttp.makeHttpRequest(url+"getrecommended_top","POST", params);
try {
products=json.getJSONArray("products");
channelForCategory.clear();
listchD.clear();
String imageViewch =null;
for(int i =0; i <products.length();i++){
JSONObject details = products.getJSONObject(i);
String pid =details.getString("pid");
String cid=details.getString("cid");
String name= details.getString("name");
Log.v("",name);
if(details.has("imageViewch")){
imageViewch = details.getString("imageViewch");}
String image_url_path= imageurl+imageViewch;
channelForCategory.add(new Video(pid,cid,name,image_url_path));
listchD.add(new Video(name,pid));
Log.w(LOG_TAG,"pid*************all************"+pid);
Log.w(LOG_TAG,"cid*********all**********"+cid);
Log.w(LOG_TAG,"name********all**********"+name);
Log.w(LOG_TAG,"imagelink*********all***********"+imageViewch);
}
} catch (JSONException e){
Log.e("SetHttp", "Problem parsing News JSON results", e);
}
return null;
// return videos;
@Override
protected void onPostExecute(List<Video> video) {
pDialog.dismiss();
ChannelRecycleViewAdapter channelRecycleViewAdapter1
= new ChannelRecycleViewAdapter(getActivity(), channelForCategory, new ChannelRecycleViewAdapter.ListItemClickListener() {
@Override
public void onListItemClick(int clickedItemIndex) {
Video videoch= channelForCategory.get(clickedItemIndex);
String urlch=videoch.getmpid();
Intent inturl= new Intent(getActivity(),VideoPlayer.class);
inturl.putExtra("urlch",urlch);
inturl.putExtra("list_video_name", (Serializable) listchD);
startActivity(inturl);
Toast.makeText(getActivity(),
urlch, Toast.LENGTH_LONG).show();
}
});
recyclerView1.setAdapter(channelRecycleViewAdapter1);
,第二个asynctask是第一个asynctask的副本。 我不知道为什么应用程序挂起并仍在加载。