Suspending threads while running multiple AsyncTasks in nested fragments and it makes app slow









up vote
13
down vote

favorite












Here I'm calling web services in nested Fragments which has TabLayout and ViewPager using AsyncTask. I've tried AsyncTasks by calling them all in onResume method of each Fragment as:



new FetchAllData(getActivity()).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);


and



new FetchAllData(getActivity()).execute();


Everything is fine but I get lots of issues:



  • App stops working without any dialog but it shows suspending all threads in logcat.


  • When we come on this fragment(which has nested tablayouts and viewpagers) from another activity which is showing in image, everything gets blank except Toolbar for 3 to 5 seconds. And all of sudden they come with complete data.


  • When we call this fragment from another fragment of same activity it freezes there and this fragments gets opened all of sudden there.


I hope you got my all issues if not please inform to me.



Stacktrace is:



1-29 12:10:49.580 10853-10863/com.cws.advisorymandi W/art: Suspending all threads took: 10.409ms
01-29 12:10:49.707 10853-10853/com.cws.advisorymandi D/cr_Ime: [InputMethodManagerWrapper.java:27] Constructor
01-29 12:10:49.711 10853-10853/com.cws.advisorymandi D/cr_Ime: [ImeAdapter.java:241] attach
01-29 12:10:49.711 10853-10853/com.cws.advisorymandi W/art: Attempt to remove local handle scope entry from IRT, ignoring
01-29 12:10:49.716 10853-10853/com.cws.advisorymandi W/AwContents: onDetachedFromWindow called when already detached. Ignoring
01-29 12:10:49.717 10853-10853/com.cws.advisorymandi D/cr_Ime: [InputMethodManagerWrapper.java:56] isActive: false
01-29 12:10:49.726 10853-10853/com.cws.advisorymandi W/art: Attempt to remove local handle scope entry from IRT, ignoring
01-29 12:10:49.726 10853-10853/com.cws.advisorymandi W/art: Attempt to remove local handle scope entry from IRT, ignoring
01-29 12:10:49.812 10853-10853/com.cws.advisorymandi D/cr_Ime: [ImeAdapter.java:241] attach
01-29 12:10:49.832 10853-10853/com.cws.advisorymandi D/cr_Ime: [ImeAdapter.java:241] attach
01-29 12:10:49.833 10853-10853/com.cws.advisorymandi I/Choreographer: Skipped 58 frames! The application may be doing too much work on its main thread.
01-29 12:10:50.075 10853-10853/com.cws.advisorymandi W/cr_BindingManager: Cannot call determinedVisibility() - never saw a connection for the pid: 10853
01-29 12:10:50.610 10853-10863/com.cws.advisorymandi W/art: Suspending all threads took: 43.636ms
01-29 12:10:50.621 10853-10853/com.cws.advisorymandi I/Ads: Scheduling ad refresh 60000 milliseconds from now.
01-29 12:10:50.630 10853-10853/com.cws.advisorymandi I/Ads: Ad finished loading.


Fragment.java



public class IndicesFragment extends android.support.v4.app.Fragment implements SwipeRefreshLayout.OnRefreshListener 
public static String imagepath = null;
public static FetchAllData myTask;
static ArrayList<EquityDetails> catListDao = new ArrayList<EquityDetails>();
static ArrayList<EquityDetails> catListDao1 = new ArrayList<EquityDetails>();
static int count = 0;
static int count1 = 0;
ListView list;
ImageView progressBar;
View view;
Activity act;
AdvisorsAdapter adapter;
TextView empty_text;
AnimatorSet set;
JSONArray jsonArray;
SwipeRefreshLayout swipeRefreshLayout;
private boolean isViewShown = false;

public static IndicesFragment newInstance()
return new IndicesFragment();


@Override
public void setUserVisibleHint(boolean isVisibleToUser)
super.setUserVisibleHint(isVisibleToUser);
if (isVisibleToUser)
isViewShown = true;
if (adapter != null)
adapter.filter("");

else
isViewShown = false;



@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
view = inflater.inflate(R.layout.equity_activity, container, false);
act = this.getActivity();
Constants.check_fragment_visible = 1;
count++;
setHasOptionsMenu(true);
list = (ListView) view.findViewById(R.id.list_equity);
empty_text = (TextView) view.findViewById(R.id.empty);
swipeRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.swipe_refresh_layout);
progressBar = (ImageView) view.findViewById(R.id.progressBar);
set = (AnimatorSet) AnimatorInflater.loadAnimator(getActivity(), R.animator.fadein);
set.setTarget(progressBar);
progressBar.setVisibility(View.GONE);
if (Utils.isNetworkAvailable(getActivity()))
if (catListDao.size() > 0)
adapter = new AdvisorsAdapter(act, R.layout.custom_equity, catListDao, 0);
list.setAdapter(adapter);
else
if (!isViewShown)
new FetchAllData(getActivity(), 3).execute();


else
CustomToast toast = new CustomToast(getActivity(), "There is no internet connection!");

swipeRefreshLayout.setOnRefreshListener(this);
return view;



public void onActivityCreated(Bundle savedInstanceState1)
super.onActivityCreated(savedInstanceState1);


@Override
public void onResume()
super.onResume();
Constants.check_fragment_visible = 1;
if (Constants.check_reload)
if (Utils.isNetworkAvailable(getActivity()))
new FetchAllData(getActivity(), 3).execute();
else
CustomToast toast = new CustomToast(getActivity(), "There is no internet connection!");


if (adapter != null) adapter.notifyDataSetChanged();



@Override
public void onRefresh()
if (Utils.isNetworkAvailable(getActivity()))
new FetchAllData(getActivity(), 3).execute();
else
CustomToast toast = new CustomToast(getActivity(), "There is no internet connection!");




public void doChange(String queryText)
if (queryText != null)
if (adapter != null)
adapter.filter(queryText);



public void parseJSON(String result)
if (result != null)
JSONObject jsonObject;
try
catListDao = new ArrayList<EquityDetails>();
jsonObject = new JSONObject(result);
jsonArray = jsonObject.getJSONArray("list");

Log.d("Length ", "" + jsonArray.length());
for (int i = 0; i < jsonArray.length(); i++)
EquityDetails allDirectory = new EquityDetails();
allDirectory.setEntry_value(jsonArray.getJSONObject(i).getString("entry"));
String value1 = jsonArray.getJSONObject(i).getString("entry");
String value2 = jsonArray.getJSONObject(i).getString("tgt_1");
allDirectory.setSerial_value(jsonArray.getJSONObject(i).getString("sl"));
allDirectory.setTg_value1(jsonArray.getJSONObject(i).getString("tgt_1"));
allDirectory.setTg_value2(jsonArray.getJSONObject(i).getString("tgt_2"));
allDirectory.setPosted_by(jsonArray.getJSONObject(i).getString("posted_by"));
allDirectory.setMainTitle_value(jsonArray.getJSONObject(i).getString("script"));
allDirectory.setMain_subTitle_value(jsonArray.getJSONObject(i).getString("exchange"));
allDirectory.setRating_value(jsonArray.getJSONObject(i).getString("rating"));
allDirectory.setReview_value(jsonArray.getJSONObject(i).getString("review"));
imagepath = jsonArray.getJSONObject(i).getString("advisor_image");
Log.d("Comminh Image ", "" + jsonArray.getJSONObject(i).getString("advisor_image"));
allDirectory.setImage1(jsonArray.getJSONObject(i).getString("advisor_image"));
allDirectory.setImage2(jsonArray.getJSONObject(i).getString("script_image"));
allDirectory.setBuy(jsonArray.getJSONObject(i).getString("buy_sentiment"));
allDirectory.setSell(jsonArray.getJSONObject(i).getString("sell_sentiment"));
allDirectory.setRecommend(jsonArray.getJSONObject(i).getString("recommendation"));
allDirectory.setPosted_date(jsonArray.getJSONObject(i).getString("posted_date"));
allDirectory.setCall_id(jsonArray.getJSONObject(i).getString("call_id"));
allDirectory.setExpiry_date(jsonArray.getJSONObject(i).getString("expiry_date"));
allDirectory.setBroker_name(jsonArray.getJSONObject(i).getString("name"));
allDirectory.setCall_detail(jsonArray.getJSONObject(i).getString("detail"));
allDirectory.setProgress_indicator(0);
catListDao.add(allDirectory);

catListDao1 = catListDao;
adapter = new AdvisorsAdapter(act, R.layout.custom_equity, catListDao, 0);
catch (JSONException e)
e.printStackTrace();






public class FetchAllData extends AsyncTask<Void, Void, String>
ProgressDialog pDialog;
int typeId;
private Context cont;

public FetchAllData(Context con, int typeId)
// TODO Auto-generated constructor stub
this.cont = con;
this.typeId = typeId;
Log.d("Constructor Called", "yes");


@Override
protected void onPreExecute()
// TODO Auto-generated method stub
super.onPreExecute();
if (!swipeRefreshLayout.isRefreshing())
if (progressBar != null)
progressBar.setVisibility(View.VISIBLE);
set.start();





@Override
protected String doInBackground(Void... params)
// TODO Auto-generated method stub
return getString();


private String getString()
// TODO Auto-generated method stub

URL obj = null;
HttpURLConnection con = null;
try
obj = new URL(Constants.AppBaseUrl + "/call_listing/" + typeId);
String userPassword = "rickmams" + ":" + "advisor11";
String header = "Basic " + new String(android.util.Base64.encode(userPassword.getBytes(), android.util.Base64.NO_WRAP));
con = (HttpURLConnection) obj.openConnection();
con.addRequestProperty("Authorization", header);
con.setRequestProperty("Content-type", "application/x-www-form-urlencoded");
con.setRequestMethod("POST");

// For POST only - BEGIN
con.setDoOutput(true);
OutputStream os = con.getOutputStream();

os.flush();
os.close();
// For POST only - END

int responseCode = con.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK) //success
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuilder response = new StringBuilder();

while ((inputLine = in.readLine()) != null)
response.append(inputLine);

in.close();
Log.i("TAG", response.toString());
parseJSON(response.toString());
return response.toString();

else
Log.i("TAG", "POST request did not work.");

catch (IOException e)
e.printStackTrace();
finally
if (con != null)
con.disconnect();


return null;



@Override
protected void onPostExecute(String result)
// TODO Auto-generated method stub
super.onPostExecute(result);
if (getActivity() == null)
return;
if (swipeRefreshLayout.isRefreshing())
swipeRefreshLayout.setRefreshing(false);

if (result != null)
if (progressBar != null)
list.setAdapter(adapter);
//pDialog.dismiss();
if (progressBar != null)
set.end();
if (progressBar.getVisibility() == View.VISIBLE)
progressBar.setVisibility(View.GONE);

if (jsonArray.length() != 0)
empty_text.setVisibility(View.GONE);
else empty_text.setVisibility(View.VISIBLE);










For complete stacktrace like go to http://pastebin.com/7FDynA05










share|improve this question























  • what if you make the asynctask run 1 by 1 without executor?
    – Randyka Yudhistira
    Jan 28 '16 at 6:44










  • It takes so much time and hangs the UI in ViewPager what I don't want
    – Anshul Tyagi
    Jan 28 '16 at 6:53










  • can you post the relevant lines of logcat and the relevant lines (thos that appear in logcat) from your code
    – Gavriel
    Jan 28 '16 at 6:59










  • Logcat is added @Gavriel
    – Anshul Tyagi
    Jan 29 '16 at 6:43














up vote
13
down vote

favorite












Here I'm calling web services in nested Fragments which has TabLayout and ViewPager using AsyncTask. I've tried AsyncTasks by calling them all in onResume method of each Fragment as:



new FetchAllData(getActivity()).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);


and



new FetchAllData(getActivity()).execute();


Everything is fine but I get lots of issues:



  • App stops working without any dialog but it shows suspending all threads in logcat.


  • When we come on this fragment(which has nested tablayouts and viewpagers) from another activity which is showing in image, everything gets blank except Toolbar for 3 to 5 seconds. And all of sudden they come with complete data.


  • When we call this fragment from another fragment of same activity it freezes there and this fragments gets opened all of sudden there.


I hope you got my all issues if not please inform to me.



Stacktrace is:



1-29 12:10:49.580 10853-10863/com.cws.advisorymandi W/art: Suspending all threads took: 10.409ms
01-29 12:10:49.707 10853-10853/com.cws.advisorymandi D/cr_Ime: [InputMethodManagerWrapper.java:27] Constructor
01-29 12:10:49.711 10853-10853/com.cws.advisorymandi D/cr_Ime: [ImeAdapter.java:241] attach
01-29 12:10:49.711 10853-10853/com.cws.advisorymandi W/art: Attempt to remove local handle scope entry from IRT, ignoring
01-29 12:10:49.716 10853-10853/com.cws.advisorymandi W/AwContents: onDetachedFromWindow called when already detached. Ignoring
01-29 12:10:49.717 10853-10853/com.cws.advisorymandi D/cr_Ime: [InputMethodManagerWrapper.java:56] isActive: false
01-29 12:10:49.726 10853-10853/com.cws.advisorymandi W/art: Attempt to remove local handle scope entry from IRT, ignoring
01-29 12:10:49.726 10853-10853/com.cws.advisorymandi W/art: Attempt to remove local handle scope entry from IRT, ignoring
01-29 12:10:49.812 10853-10853/com.cws.advisorymandi D/cr_Ime: [ImeAdapter.java:241] attach
01-29 12:10:49.832 10853-10853/com.cws.advisorymandi D/cr_Ime: [ImeAdapter.java:241] attach
01-29 12:10:49.833 10853-10853/com.cws.advisorymandi I/Choreographer: Skipped 58 frames! The application may be doing too much work on its main thread.
01-29 12:10:50.075 10853-10853/com.cws.advisorymandi W/cr_BindingManager: Cannot call determinedVisibility() - never saw a connection for the pid: 10853
01-29 12:10:50.610 10853-10863/com.cws.advisorymandi W/art: Suspending all threads took: 43.636ms
01-29 12:10:50.621 10853-10853/com.cws.advisorymandi I/Ads: Scheduling ad refresh 60000 milliseconds from now.
01-29 12:10:50.630 10853-10853/com.cws.advisorymandi I/Ads: Ad finished loading.


Fragment.java



public class IndicesFragment extends android.support.v4.app.Fragment implements SwipeRefreshLayout.OnRefreshListener 
public static String imagepath = null;
public static FetchAllData myTask;
static ArrayList<EquityDetails> catListDao = new ArrayList<EquityDetails>();
static ArrayList<EquityDetails> catListDao1 = new ArrayList<EquityDetails>();
static int count = 0;
static int count1 = 0;
ListView list;
ImageView progressBar;
View view;
Activity act;
AdvisorsAdapter adapter;
TextView empty_text;
AnimatorSet set;
JSONArray jsonArray;
SwipeRefreshLayout swipeRefreshLayout;
private boolean isViewShown = false;

public static IndicesFragment newInstance()
return new IndicesFragment();


@Override
public void setUserVisibleHint(boolean isVisibleToUser)
super.setUserVisibleHint(isVisibleToUser);
if (isVisibleToUser)
isViewShown = true;
if (adapter != null)
adapter.filter("");

else
isViewShown = false;



@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
view = inflater.inflate(R.layout.equity_activity, container, false);
act = this.getActivity();
Constants.check_fragment_visible = 1;
count++;
setHasOptionsMenu(true);
list = (ListView) view.findViewById(R.id.list_equity);
empty_text = (TextView) view.findViewById(R.id.empty);
swipeRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.swipe_refresh_layout);
progressBar = (ImageView) view.findViewById(R.id.progressBar);
set = (AnimatorSet) AnimatorInflater.loadAnimator(getActivity(), R.animator.fadein);
set.setTarget(progressBar);
progressBar.setVisibility(View.GONE);
if (Utils.isNetworkAvailable(getActivity()))
if (catListDao.size() > 0)
adapter = new AdvisorsAdapter(act, R.layout.custom_equity, catListDao, 0);
list.setAdapter(adapter);
else
if (!isViewShown)
new FetchAllData(getActivity(), 3).execute();


else
CustomToast toast = new CustomToast(getActivity(), "There is no internet connection!");

swipeRefreshLayout.setOnRefreshListener(this);
return view;



public void onActivityCreated(Bundle savedInstanceState1)
super.onActivityCreated(savedInstanceState1);


@Override
public void onResume()
super.onResume();
Constants.check_fragment_visible = 1;
if (Constants.check_reload)
if (Utils.isNetworkAvailable(getActivity()))
new FetchAllData(getActivity(), 3).execute();
else
CustomToast toast = new CustomToast(getActivity(), "There is no internet connection!");


if (adapter != null) adapter.notifyDataSetChanged();



@Override
public void onRefresh()
if (Utils.isNetworkAvailable(getActivity()))
new FetchAllData(getActivity(), 3).execute();
else
CustomToast toast = new CustomToast(getActivity(), "There is no internet connection!");




public void doChange(String queryText)
if (queryText != null)
if (adapter != null)
adapter.filter(queryText);



public void parseJSON(String result)
if (result != null)
JSONObject jsonObject;
try
catListDao = new ArrayList<EquityDetails>();
jsonObject = new JSONObject(result);
jsonArray = jsonObject.getJSONArray("list");

Log.d("Length ", "" + jsonArray.length());
for (int i = 0; i < jsonArray.length(); i++)
EquityDetails allDirectory = new EquityDetails();
allDirectory.setEntry_value(jsonArray.getJSONObject(i).getString("entry"));
String value1 = jsonArray.getJSONObject(i).getString("entry");
String value2 = jsonArray.getJSONObject(i).getString("tgt_1");
allDirectory.setSerial_value(jsonArray.getJSONObject(i).getString("sl"));
allDirectory.setTg_value1(jsonArray.getJSONObject(i).getString("tgt_1"));
allDirectory.setTg_value2(jsonArray.getJSONObject(i).getString("tgt_2"));
allDirectory.setPosted_by(jsonArray.getJSONObject(i).getString("posted_by"));
allDirectory.setMainTitle_value(jsonArray.getJSONObject(i).getString("script"));
allDirectory.setMain_subTitle_value(jsonArray.getJSONObject(i).getString("exchange"));
allDirectory.setRating_value(jsonArray.getJSONObject(i).getString("rating"));
allDirectory.setReview_value(jsonArray.getJSONObject(i).getString("review"));
imagepath = jsonArray.getJSONObject(i).getString("advisor_image");
Log.d("Comminh Image ", "" + jsonArray.getJSONObject(i).getString("advisor_image"));
allDirectory.setImage1(jsonArray.getJSONObject(i).getString("advisor_image"));
allDirectory.setImage2(jsonArray.getJSONObject(i).getString("script_image"));
allDirectory.setBuy(jsonArray.getJSONObject(i).getString("buy_sentiment"));
allDirectory.setSell(jsonArray.getJSONObject(i).getString("sell_sentiment"));
allDirectory.setRecommend(jsonArray.getJSONObject(i).getString("recommendation"));
allDirectory.setPosted_date(jsonArray.getJSONObject(i).getString("posted_date"));
allDirectory.setCall_id(jsonArray.getJSONObject(i).getString("call_id"));
allDirectory.setExpiry_date(jsonArray.getJSONObject(i).getString("expiry_date"));
allDirectory.setBroker_name(jsonArray.getJSONObject(i).getString("name"));
allDirectory.setCall_detail(jsonArray.getJSONObject(i).getString("detail"));
allDirectory.setProgress_indicator(0);
catListDao.add(allDirectory);

catListDao1 = catListDao;
adapter = new AdvisorsAdapter(act, R.layout.custom_equity, catListDao, 0);
catch (JSONException e)
e.printStackTrace();






public class FetchAllData extends AsyncTask<Void, Void, String>
ProgressDialog pDialog;
int typeId;
private Context cont;

public FetchAllData(Context con, int typeId)
// TODO Auto-generated constructor stub
this.cont = con;
this.typeId = typeId;
Log.d("Constructor Called", "yes");


@Override
protected void onPreExecute()
// TODO Auto-generated method stub
super.onPreExecute();
if (!swipeRefreshLayout.isRefreshing())
if (progressBar != null)
progressBar.setVisibility(View.VISIBLE);
set.start();





@Override
protected String doInBackground(Void... params)
// TODO Auto-generated method stub
return getString();


private String getString()
// TODO Auto-generated method stub

URL obj = null;
HttpURLConnection con = null;
try
obj = new URL(Constants.AppBaseUrl + "/call_listing/" + typeId);
String userPassword = "rickmams" + ":" + "advisor11";
String header = "Basic " + new String(android.util.Base64.encode(userPassword.getBytes(), android.util.Base64.NO_WRAP));
con = (HttpURLConnection) obj.openConnection();
con.addRequestProperty("Authorization", header);
con.setRequestProperty("Content-type", "application/x-www-form-urlencoded");
con.setRequestMethod("POST");

// For POST only - BEGIN
con.setDoOutput(true);
OutputStream os = con.getOutputStream();

os.flush();
os.close();
// For POST only - END

int responseCode = con.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK) //success
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuilder response = new StringBuilder();

while ((inputLine = in.readLine()) != null)
response.append(inputLine);

in.close();
Log.i("TAG", response.toString());
parseJSON(response.toString());
return response.toString();

else
Log.i("TAG", "POST request did not work.");

catch (IOException e)
e.printStackTrace();
finally
if (con != null)
con.disconnect();


return null;



@Override
protected void onPostExecute(String result)
// TODO Auto-generated method stub
super.onPostExecute(result);
if (getActivity() == null)
return;
if (swipeRefreshLayout.isRefreshing())
swipeRefreshLayout.setRefreshing(false);

if (result != null)
if (progressBar != null)
list.setAdapter(adapter);
//pDialog.dismiss();
if (progressBar != null)
set.end();
if (progressBar.getVisibility() == View.VISIBLE)
progressBar.setVisibility(View.GONE);

if (jsonArray.length() != 0)
empty_text.setVisibility(View.GONE);
else empty_text.setVisibility(View.VISIBLE);










For complete stacktrace like go to http://pastebin.com/7FDynA05










share|improve this question























  • what if you make the asynctask run 1 by 1 without executor?
    – Randyka Yudhistira
    Jan 28 '16 at 6:44










  • It takes so much time and hangs the UI in ViewPager what I don't want
    – Anshul Tyagi
    Jan 28 '16 at 6:53










  • can you post the relevant lines of logcat and the relevant lines (thos that appear in logcat) from your code
    – Gavriel
    Jan 28 '16 at 6:59










  • Logcat is added @Gavriel
    – Anshul Tyagi
    Jan 29 '16 at 6:43












up vote
13
down vote

favorite









up vote
13
down vote

favorite











Here I'm calling web services in nested Fragments which has TabLayout and ViewPager using AsyncTask. I've tried AsyncTasks by calling them all in onResume method of each Fragment as:



new FetchAllData(getActivity()).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);


and



new FetchAllData(getActivity()).execute();


Everything is fine but I get lots of issues:



  • App stops working without any dialog but it shows suspending all threads in logcat.


  • When we come on this fragment(which has nested tablayouts and viewpagers) from another activity which is showing in image, everything gets blank except Toolbar for 3 to 5 seconds. And all of sudden they come with complete data.


  • When we call this fragment from another fragment of same activity it freezes there and this fragments gets opened all of sudden there.


I hope you got my all issues if not please inform to me.



Stacktrace is:



1-29 12:10:49.580 10853-10863/com.cws.advisorymandi W/art: Suspending all threads took: 10.409ms
01-29 12:10:49.707 10853-10853/com.cws.advisorymandi D/cr_Ime: [InputMethodManagerWrapper.java:27] Constructor
01-29 12:10:49.711 10853-10853/com.cws.advisorymandi D/cr_Ime: [ImeAdapter.java:241] attach
01-29 12:10:49.711 10853-10853/com.cws.advisorymandi W/art: Attempt to remove local handle scope entry from IRT, ignoring
01-29 12:10:49.716 10853-10853/com.cws.advisorymandi W/AwContents: onDetachedFromWindow called when already detached. Ignoring
01-29 12:10:49.717 10853-10853/com.cws.advisorymandi D/cr_Ime: [InputMethodManagerWrapper.java:56] isActive: false
01-29 12:10:49.726 10853-10853/com.cws.advisorymandi W/art: Attempt to remove local handle scope entry from IRT, ignoring
01-29 12:10:49.726 10853-10853/com.cws.advisorymandi W/art: Attempt to remove local handle scope entry from IRT, ignoring
01-29 12:10:49.812 10853-10853/com.cws.advisorymandi D/cr_Ime: [ImeAdapter.java:241] attach
01-29 12:10:49.832 10853-10853/com.cws.advisorymandi D/cr_Ime: [ImeAdapter.java:241] attach
01-29 12:10:49.833 10853-10853/com.cws.advisorymandi I/Choreographer: Skipped 58 frames! The application may be doing too much work on its main thread.
01-29 12:10:50.075 10853-10853/com.cws.advisorymandi W/cr_BindingManager: Cannot call determinedVisibility() - never saw a connection for the pid: 10853
01-29 12:10:50.610 10853-10863/com.cws.advisorymandi W/art: Suspending all threads took: 43.636ms
01-29 12:10:50.621 10853-10853/com.cws.advisorymandi I/Ads: Scheduling ad refresh 60000 milliseconds from now.
01-29 12:10:50.630 10853-10853/com.cws.advisorymandi I/Ads: Ad finished loading.


Fragment.java



public class IndicesFragment extends android.support.v4.app.Fragment implements SwipeRefreshLayout.OnRefreshListener 
public static String imagepath = null;
public static FetchAllData myTask;
static ArrayList<EquityDetails> catListDao = new ArrayList<EquityDetails>();
static ArrayList<EquityDetails> catListDao1 = new ArrayList<EquityDetails>();
static int count = 0;
static int count1 = 0;
ListView list;
ImageView progressBar;
View view;
Activity act;
AdvisorsAdapter adapter;
TextView empty_text;
AnimatorSet set;
JSONArray jsonArray;
SwipeRefreshLayout swipeRefreshLayout;
private boolean isViewShown = false;

public static IndicesFragment newInstance()
return new IndicesFragment();


@Override
public void setUserVisibleHint(boolean isVisibleToUser)
super.setUserVisibleHint(isVisibleToUser);
if (isVisibleToUser)
isViewShown = true;
if (adapter != null)
adapter.filter("");

else
isViewShown = false;



@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
view = inflater.inflate(R.layout.equity_activity, container, false);
act = this.getActivity();
Constants.check_fragment_visible = 1;
count++;
setHasOptionsMenu(true);
list = (ListView) view.findViewById(R.id.list_equity);
empty_text = (TextView) view.findViewById(R.id.empty);
swipeRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.swipe_refresh_layout);
progressBar = (ImageView) view.findViewById(R.id.progressBar);
set = (AnimatorSet) AnimatorInflater.loadAnimator(getActivity(), R.animator.fadein);
set.setTarget(progressBar);
progressBar.setVisibility(View.GONE);
if (Utils.isNetworkAvailable(getActivity()))
if (catListDao.size() > 0)
adapter = new AdvisorsAdapter(act, R.layout.custom_equity, catListDao, 0);
list.setAdapter(adapter);
else
if (!isViewShown)
new FetchAllData(getActivity(), 3).execute();


else
CustomToast toast = new CustomToast(getActivity(), "There is no internet connection!");

swipeRefreshLayout.setOnRefreshListener(this);
return view;



public void onActivityCreated(Bundle savedInstanceState1)
super.onActivityCreated(savedInstanceState1);


@Override
public void onResume()
super.onResume();
Constants.check_fragment_visible = 1;
if (Constants.check_reload)
if (Utils.isNetworkAvailable(getActivity()))
new FetchAllData(getActivity(), 3).execute();
else
CustomToast toast = new CustomToast(getActivity(), "There is no internet connection!");


if (adapter != null) adapter.notifyDataSetChanged();



@Override
public void onRefresh()
if (Utils.isNetworkAvailable(getActivity()))
new FetchAllData(getActivity(), 3).execute();
else
CustomToast toast = new CustomToast(getActivity(), "There is no internet connection!");




public void doChange(String queryText)
if (queryText != null)
if (adapter != null)
adapter.filter(queryText);



public void parseJSON(String result)
if (result != null)
JSONObject jsonObject;
try
catListDao = new ArrayList<EquityDetails>();
jsonObject = new JSONObject(result);
jsonArray = jsonObject.getJSONArray("list");

Log.d("Length ", "" + jsonArray.length());
for (int i = 0; i < jsonArray.length(); i++)
EquityDetails allDirectory = new EquityDetails();
allDirectory.setEntry_value(jsonArray.getJSONObject(i).getString("entry"));
String value1 = jsonArray.getJSONObject(i).getString("entry");
String value2 = jsonArray.getJSONObject(i).getString("tgt_1");
allDirectory.setSerial_value(jsonArray.getJSONObject(i).getString("sl"));
allDirectory.setTg_value1(jsonArray.getJSONObject(i).getString("tgt_1"));
allDirectory.setTg_value2(jsonArray.getJSONObject(i).getString("tgt_2"));
allDirectory.setPosted_by(jsonArray.getJSONObject(i).getString("posted_by"));
allDirectory.setMainTitle_value(jsonArray.getJSONObject(i).getString("script"));
allDirectory.setMain_subTitle_value(jsonArray.getJSONObject(i).getString("exchange"));
allDirectory.setRating_value(jsonArray.getJSONObject(i).getString("rating"));
allDirectory.setReview_value(jsonArray.getJSONObject(i).getString("review"));
imagepath = jsonArray.getJSONObject(i).getString("advisor_image");
Log.d("Comminh Image ", "" + jsonArray.getJSONObject(i).getString("advisor_image"));
allDirectory.setImage1(jsonArray.getJSONObject(i).getString("advisor_image"));
allDirectory.setImage2(jsonArray.getJSONObject(i).getString("script_image"));
allDirectory.setBuy(jsonArray.getJSONObject(i).getString("buy_sentiment"));
allDirectory.setSell(jsonArray.getJSONObject(i).getString("sell_sentiment"));
allDirectory.setRecommend(jsonArray.getJSONObject(i).getString("recommendation"));
allDirectory.setPosted_date(jsonArray.getJSONObject(i).getString("posted_date"));
allDirectory.setCall_id(jsonArray.getJSONObject(i).getString("call_id"));
allDirectory.setExpiry_date(jsonArray.getJSONObject(i).getString("expiry_date"));
allDirectory.setBroker_name(jsonArray.getJSONObject(i).getString("name"));
allDirectory.setCall_detail(jsonArray.getJSONObject(i).getString("detail"));
allDirectory.setProgress_indicator(0);
catListDao.add(allDirectory);

catListDao1 = catListDao;
adapter = new AdvisorsAdapter(act, R.layout.custom_equity, catListDao, 0);
catch (JSONException e)
e.printStackTrace();






public class FetchAllData extends AsyncTask<Void, Void, String>
ProgressDialog pDialog;
int typeId;
private Context cont;

public FetchAllData(Context con, int typeId)
// TODO Auto-generated constructor stub
this.cont = con;
this.typeId = typeId;
Log.d("Constructor Called", "yes");


@Override
protected void onPreExecute()
// TODO Auto-generated method stub
super.onPreExecute();
if (!swipeRefreshLayout.isRefreshing())
if (progressBar != null)
progressBar.setVisibility(View.VISIBLE);
set.start();





@Override
protected String doInBackground(Void... params)
// TODO Auto-generated method stub
return getString();


private String getString()
// TODO Auto-generated method stub

URL obj = null;
HttpURLConnection con = null;
try
obj = new URL(Constants.AppBaseUrl + "/call_listing/" + typeId);
String userPassword = "rickmams" + ":" + "advisor11";
String header = "Basic " + new String(android.util.Base64.encode(userPassword.getBytes(), android.util.Base64.NO_WRAP));
con = (HttpURLConnection) obj.openConnection();
con.addRequestProperty("Authorization", header);
con.setRequestProperty("Content-type", "application/x-www-form-urlencoded");
con.setRequestMethod("POST");

// For POST only - BEGIN
con.setDoOutput(true);
OutputStream os = con.getOutputStream();

os.flush();
os.close();
// For POST only - END

int responseCode = con.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK) //success
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuilder response = new StringBuilder();

while ((inputLine = in.readLine()) != null)
response.append(inputLine);

in.close();
Log.i("TAG", response.toString());
parseJSON(response.toString());
return response.toString();

else
Log.i("TAG", "POST request did not work.");

catch (IOException e)
e.printStackTrace();
finally
if (con != null)
con.disconnect();


return null;



@Override
protected void onPostExecute(String result)
// TODO Auto-generated method stub
super.onPostExecute(result);
if (getActivity() == null)
return;
if (swipeRefreshLayout.isRefreshing())
swipeRefreshLayout.setRefreshing(false);

if (result != null)
if (progressBar != null)
list.setAdapter(adapter);
//pDialog.dismiss();
if (progressBar != null)
set.end();
if (progressBar.getVisibility() == View.VISIBLE)
progressBar.setVisibility(View.GONE);

if (jsonArray.length() != 0)
empty_text.setVisibility(View.GONE);
else empty_text.setVisibility(View.VISIBLE);










For complete stacktrace like go to http://pastebin.com/7FDynA05










share|improve this question















Here I'm calling web services in nested Fragments which has TabLayout and ViewPager using AsyncTask. I've tried AsyncTasks by calling them all in onResume method of each Fragment as:



new FetchAllData(getActivity()).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);


and



new FetchAllData(getActivity()).execute();


Everything is fine but I get lots of issues:



  • App stops working without any dialog but it shows suspending all threads in logcat.


  • When we come on this fragment(which has nested tablayouts and viewpagers) from another activity which is showing in image, everything gets blank except Toolbar for 3 to 5 seconds. And all of sudden they come with complete data.


  • When we call this fragment from another fragment of same activity it freezes there and this fragments gets opened all of sudden there.


I hope you got my all issues if not please inform to me.



Stacktrace is:



1-29 12:10:49.580 10853-10863/com.cws.advisorymandi W/art: Suspending all threads took: 10.409ms
01-29 12:10:49.707 10853-10853/com.cws.advisorymandi D/cr_Ime: [InputMethodManagerWrapper.java:27] Constructor
01-29 12:10:49.711 10853-10853/com.cws.advisorymandi D/cr_Ime: [ImeAdapter.java:241] attach
01-29 12:10:49.711 10853-10853/com.cws.advisorymandi W/art: Attempt to remove local handle scope entry from IRT, ignoring
01-29 12:10:49.716 10853-10853/com.cws.advisorymandi W/AwContents: onDetachedFromWindow called when already detached. Ignoring
01-29 12:10:49.717 10853-10853/com.cws.advisorymandi D/cr_Ime: [InputMethodManagerWrapper.java:56] isActive: false
01-29 12:10:49.726 10853-10853/com.cws.advisorymandi W/art: Attempt to remove local handle scope entry from IRT, ignoring
01-29 12:10:49.726 10853-10853/com.cws.advisorymandi W/art: Attempt to remove local handle scope entry from IRT, ignoring
01-29 12:10:49.812 10853-10853/com.cws.advisorymandi D/cr_Ime: [ImeAdapter.java:241] attach
01-29 12:10:49.832 10853-10853/com.cws.advisorymandi D/cr_Ime: [ImeAdapter.java:241] attach
01-29 12:10:49.833 10853-10853/com.cws.advisorymandi I/Choreographer: Skipped 58 frames! The application may be doing too much work on its main thread.
01-29 12:10:50.075 10853-10853/com.cws.advisorymandi W/cr_BindingManager: Cannot call determinedVisibility() - never saw a connection for the pid: 10853
01-29 12:10:50.610 10853-10863/com.cws.advisorymandi W/art: Suspending all threads took: 43.636ms
01-29 12:10:50.621 10853-10853/com.cws.advisorymandi I/Ads: Scheduling ad refresh 60000 milliseconds from now.
01-29 12:10:50.630 10853-10853/com.cws.advisorymandi I/Ads: Ad finished loading.


Fragment.java



public class IndicesFragment extends android.support.v4.app.Fragment implements SwipeRefreshLayout.OnRefreshListener 
public static String imagepath = null;
public static FetchAllData myTask;
static ArrayList<EquityDetails> catListDao = new ArrayList<EquityDetails>();
static ArrayList<EquityDetails> catListDao1 = new ArrayList<EquityDetails>();
static int count = 0;
static int count1 = 0;
ListView list;
ImageView progressBar;
View view;
Activity act;
AdvisorsAdapter adapter;
TextView empty_text;
AnimatorSet set;
JSONArray jsonArray;
SwipeRefreshLayout swipeRefreshLayout;
private boolean isViewShown = false;

public static IndicesFragment newInstance()
return new IndicesFragment();


@Override
public void setUserVisibleHint(boolean isVisibleToUser)
super.setUserVisibleHint(isVisibleToUser);
if (isVisibleToUser)
isViewShown = true;
if (adapter != null)
adapter.filter("");

else
isViewShown = false;



@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
view = inflater.inflate(R.layout.equity_activity, container, false);
act = this.getActivity();
Constants.check_fragment_visible = 1;
count++;
setHasOptionsMenu(true);
list = (ListView) view.findViewById(R.id.list_equity);
empty_text = (TextView) view.findViewById(R.id.empty);
swipeRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.swipe_refresh_layout);
progressBar = (ImageView) view.findViewById(R.id.progressBar);
set = (AnimatorSet) AnimatorInflater.loadAnimator(getActivity(), R.animator.fadein);
set.setTarget(progressBar);
progressBar.setVisibility(View.GONE);
if (Utils.isNetworkAvailable(getActivity()))
if (catListDao.size() > 0)
adapter = new AdvisorsAdapter(act, R.layout.custom_equity, catListDao, 0);
list.setAdapter(adapter);
else
if (!isViewShown)
new FetchAllData(getActivity(), 3).execute();


else
CustomToast toast = new CustomToast(getActivity(), "There is no internet connection!");

swipeRefreshLayout.setOnRefreshListener(this);
return view;



public void onActivityCreated(Bundle savedInstanceState1)
super.onActivityCreated(savedInstanceState1);


@Override
public void onResume()
super.onResume();
Constants.check_fragment_visible = 1;
if (Constants.check_reload)
if (Utils.isNetworkAvailable(getActivity()))
new FetchAllData(getActivity(), 3).execute();
else
CustomToast toast = new CustomToast(getActivity(), "There is no internet connection!");


if (adapter != null) adapter.notifyDataSetChanged();



@Override
public void onRefresh()
if (Utils.isNetworkAvailable(getActivity()))
new FetchAllData(getActivity(), 3).execute();
else
CustomToast toast = new CustomToast(getActivity(), "There is no internet connection!");




public void doChange(String queryText)
if (queryText != null)
if (adapter != null)
adapter.filter(queryText);



public void parseJSON(String result)
if (result != null)
JSONObject jsonObject;
try
catListDao = new ArrayList<EquityDetails>();
jsonObject = new JSONObject(result);
jsonArray = jsonObject.getJSONArray("list");

Log.d("Length ", "" + jsonArray.length());
for (int i = 0; i < jsonArray.length(); i++)
EquityDetails allDirectory = new EquityDetails();
allDirectory.setEntry_value(jsonArray.getJSONObject(i).getString("entry"));
String value1 = jsonArray.getJSONObject(i).getString("entry");
String value2 = jsonArray.getJSONObject(i).getString("tgt_1");
allDirectory.setSerial_value(jsonArray.getJSONObject(i).getString("sl"));
allDirectory.setTg_value1(jsonArray.getJSONObject(i).getString("tgt_1"));
allDirectory.setTg_value2(jsonArray.getJSONObject(i).getString("tgt_2"));
allDirectory.setPosted_by(jsonArray.getJSONObject(i).getString("posted_by"));
allDirectory.setMainTitle_value(jsonArray.getJSONObject(i).getString("script"));
allDirectory.setMain_subTitle_value(jsonArray.getJSONObject(i).getString("exchange"));
allDirectory.setRating_value(jsonArray.getJSONObject(i).getString("rating"));
allDirectory.setReview_value(jsonArray.getJSONObject(i).getString("review"));
imagepath = jsonArray.getJSONObject(i).getString("advisor_image");
Log.d("Comminh Image ", "" + jsonArray.getJSONObject(i).getString("advisor_image"));
allDirectory.setImage1(jsonArray.getJSONObject(i).getString("advisor_image"));
allDirectory.setImage2(jsonArray.getJSONObject(i).getString("script_image"));
allDirectory.setBuy(jsonArray.getJSONObject(i).getString("buy_sentiment"));
allDirectory.setSell(jsonArray.getJSONObject(i).getString("sell_sentiment"));
allDirectory.setRecommend(jsonArray.getJSONObject(i).getString("recommendation"));
allDirectory.setPosted_date(jsonArray.getJSONObject(i).getString("posted_date"));
allDirectory.setCall_id(jsonArray.getJSONObject(i).getString("call_id"));
allDirectory.setExpiry_date(jsonArray.getJSONObject(i).getString("expiry_date"));
allDirectory.setBroker_name(jsonArray.getJSONObject(i).getString("name"));
allDirectory.setCall_detail(jsonArray.getJSONObject(i).getString("detail"));
allDirectory.setProgress_indicator(0);
catListDao.add(allDirectory);

catListDao1 = catListDao;
adapter = new AdvisorsAdapter(act, R.layout.custom_equity, catListDao, 0);
catch (JSONException e)
e.printStackTrace();






public class FetchAllData extends AsyncTask<Void, Void, String>
ProgressDialog pDialog;
int typeId;
private Context cont;

public FetchAllData(Context con, int typeId)
// TODO Auto-generated constructor stub
this.cont = con;
this.typeId = typeId;
Log.d("Constructor Called", "yes");


@Override
protected void onPreExecute()
// TODO Auto-generated method stub
super.onPreExecute();
if (!swipeRefreshLayout.isRefreshing())
if (progressBar != null)
progressBar.setVisibility(View.VISIBLE);
set.start();





@Override
protected String doInBackground(Void... params)
// TODO Auto-generated method stub
return getString();


private String getString()
// TODO Auto-generated method stub

URL obj = null;
HttpURLConnection con = null;
try
obj = new URL(Constants.AppBaseUrl + "/call_listing/" + typeId);
String userPassword = "rickmams" + ":" + "advisor11";
String header = "Basic " + new String(android.util.Base64.encode(userPassword.getBytes(), android.util.Base64.NO_WRAP));
con = (HttpURLConnection) obj.openConnection();
con.addRequestProperty("Authorization", header);
con.setRequestProperty("Content-type", "application/x-www-form-urlencoded");
con.setRequestMethod("POST");

// For POST only - BEGIN
con.setDoOutput(true);
OutputStream os = con.getOutputStream();

os.flush();
os.close();
// For POST only - END

int responseCode = con.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK) //success
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuilder response = new StringBuilder();

while ((inputLine = in.readLine()) != null)
response.append(inputLine);

in.close();
Log.i("TAG", response.toString());
parseJSON(response.toString());
return response.toString();

else
Log.i("TAG", "POST request did not work.");

catch (IOException e)
e.printStackTrace();
finally
if (con != null)
con.disconnect();


return null;



@Override
protected void onPostExecute(String result)
// TODO Auto-generated method stub
super.onPostExecute(result);
if (getActivity() == null)
return;
if (swipeRefreshLayout.isRefreshing())
swipeRefreshLayout.setRefreshing(false);

if (result != null)
if (progressBar != null)
list.setAdapter(adapter);
//pDialog.dismiss();
if (progressBar != null)
set.end();
if (progressBar.getVisibility() == View.VISIBLE)
progressBar.setVisibility(View.GONE);

if (jsonArray.length() != 0)
empty_text.setVisibility(View.GONE);
else empty_text.setVisibility(View.VISIBLE);










For complete stacktrace like go to http://pastebin.com/7FDynA05







android multithreading user-interface android-fragments android-asynctask






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 10 at 12:01









marc_s

568k12810991249




568k12810991249










asked Jan 28 '16 at 6:39









Anshul Tyagi

1,32031741




1,32031741











  • what if you make the asynctask run 1 by 1 without executor?
    – Randyka Yudhistira
    Jan 28 '16 at 6:44










  • It takes so much time and hangs the UI in ViewPager what I don't want
    – Anshul Tyagi
    Jan 28 '16 at 6:53










  • can you post the relevant lines of logcat and the relevant lines (thos that appear in logcat) from your code
    – Gavriel
    Jan 28 '16 at 6:59










  • Logcat is added @Gavriel
    – Anshul Tyagi
    Jan 29 '16 at 6:43
















  • what if you make the asynctask run 1 by 1 without executor?
    – Randyka Yudhistira
    Jan 28 '16 at 6:44










  • It takes so much time and hangs the UI in ViewPager what I don't want
    – Anshul Tyagi
    Jan 28 '16 at 6:53










  • can you post the relevant lines of logcat and the relevant lines (thos that appear in logcat) from your code
    – Gavriel
    Jan 28 '16 at 6:59










  • Logcat is added @Gavriel
    – Anshul Tyagi
    Jan 29 '16 at 6:43















what if you make the asynctask run 1 by 1 without executor?
– Randyka Yudhistira
Jan 28 '16 at 6:44




what if you make the asynctask run 1 by 1 without executor?
– Randyka Yudhistira
Jan 28 '16 at 6:44












It takes so much time and hangs the UI in ViewPager what I don't want
– Anshul Tyagi
Jan 28 '16 at 6:53




It takes so much time and hangs the UI in ViewPager what I don't want
– Anshul Tyagi
Jan 28 '16 at 6:53












can you post the relevant lines of logcat and the relevant lines (thos that appear in logcat) from your code
– Gavriel
Jan 28 '16 at 6:59




can you post the relevant lines of logcat and the relevant lines (thos that appear in logcat) from your code
– Gavriel
Jan 28 '16 at 6:59












Logcat is added @Gavriel
– Anshul Tyagi
Jan 29 '16 at 6:43




Logcat is added @Gavriel
– Anshul Tyagi
Jan 29 '16 at 6:43












3 Answers
3






active

oldest

votes

















up vote
2
down vote



accepted










I know I'm late but as I saw your lots of questions regarding of processing of app I found no error in anything but still I wanna say please check if you're calling any TypeFace by creating a new object each time so comment them and run your code and let me know.



I've also faced this type of issue a long time ago just beacuse of TypeFace so please give a try to my answer and let me know.



Thanks.






share|improve this answer




















  • Ok wait let me do. I also faced this issue for scrolling of ListView
    – Anshul Tyagi
    Mar 22 '16 at 5:30


















up vote
1
down vote













Firstly i would recommend you to use any network library can be volley or retrofit. As they are more efficient and they will handle the call in background and parallely without using AsyncTask.



The way you are trying is most sophisticated, as are you calling concurrently.



If it's required, then only make network call on resume. Rest you can call it in onCreateView. Or you can even choose to call it in on start.






share|improve this answer






















  • I tried volley but got same result.
    – Anshul Tyagi
    Mar 7 '16 at 1:31










  • @AnshulTyagi Is your volley instance is singleton ? If not, it's behaving same and executing every call concurrently, make it singleton.
    – UMESH0492
    Mar 7 '16 at 7:39







  • 1




    I would highly recommend retrofit over volley. You have a lot more freedom.
    – Jared Burrows
    Mar 7 '16 at 8:06










  • @JaredBurrows where will I execute them? In onResume() of fragments?
    – Anshul Tyagi
    Mar 7 '16 at 10:09










  • @AnshulTyagi don't do more work in onResume, if not required . As there are lots of child fragment you have used, which are calling asynctask concurrently doing so causing system to suspend the threads to avoid freezing .
    – UMESH0492
    Mar 7 '16 at 11:01

















up vote
0
down vote













Don't do heavy operation within activities or fragments, or every time you modify the user interface you will have to manage problems (with async task too).



You can use asynch task or library such as volley, but with services. A good tutorial is here.






share|improve this answer




















  • You mean I need to hit each service in each fragment by using a background service?
    – Anshul Tyagi
    Mar 7 '16 at 10:18










  • I mean is better put I/O and network code in a service and then handle it from fragment and activity through intent and message. This approach separate activity lifecycle from network operations.
    – xcesco
    Mar 7 '16 at 11:53










  • You added a link which tells How to use Service not how we manage multiple asynctasks of different fragments by using a Single Service class.
    – Anshul Tyagi
    Mar 8 '16 at 5:31










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f35054425%2fsuspending-threads-while-running-multiple-asynctasks-in-nested-fragments-and-it%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























3 Answers
3






active

oldest

votes








3 Answers
3






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
2
down vote



accepted










I know I'm late but as I saw your lots of questions regarding of processing of app I found no error in anything but still I wanna say please check if you're calling any TypeFace by creating a new object each time so comment them and run your code and let me know.



I've also faced this type of issue a long time ago just beacuse of TypeFace so please give a try to my answer and let me know.



Thanks.






share|improve this answer




















  • Ok wait let me do. I also faced this issue for scrolling of ListView
    – Anshul Tyagi
    Mar 22 '16 at 5:30















up vote
2
down vote



accepted










I know I'm late but as I saw your lots of questions regarding of processing of app I found no error in anything but still I wanna say please check if you're calling any TypeFace by creating a new object each time so comment them and run your code and let me know.



I've also faced this type of issue a long time ago just beacuse of TypeFace so please give a try to my answer and let me know.



Thanks.






share|improve this answer




















  • Ok wait let me do. I also faced this issue for scrolling of ListView
    – Anshul Tyagi
    Mar 22 '16 at 5:30













up vote
2
down vote



accepted







up vote
2
down vote



accepted






I know I'm late but as I saw your lots of questions regarding of processing of app I found no error in anything but still I wanna say please check if you're calling any TypeFace by creating a new object each time so comment them and run your code and let me know.



I've also faced this type of issue a long time ago just beacuse of TypeFace so please give a try to my answer and let me know.



Thanks.






share|improve this answer












I know I'm late but as I saw your lots of questions regarding of processing of app I found no error in anything but still I wanna say please check if you're calling any TypeFace by creating a new object each time so comment them and run your code and let me know.



I've also faced this type of issue a long time ago just beacuse of TypeFace so please give a try to my answer and let me know.



Thanks.







share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 22 '16 at 5:29









Anshul Sharma

695




695











  • Ok wait let me do. I also faced this issue for scrolling of ListView
    – Anshul Tyagi
    Mar 22 '16 at 5:30

















  • Ok wait let me do. I also faced this issue for scrolling of ListView
    – Anshul Tyagi
    Mar 22 '16 at 5:30
















Ok wait let me do. I also faced this issue for scrolling of ListView
– Anshul Tyagi
Mar 22 '16 at 5:30





Ok wait let me do. I also faced this issue for scrolling of ListView
– Anshul Tyagi
Mar 22 '16 at 5:30













up vote
1
down vote













Firstly i would recommend you to use any network library can be volley or retrofit. As they are more efficient and they will handle the call in background and parallely without using AsyncTask.



The way you are trying is most sophisticated, as are you calling concurrently.



If it's required, then only make network call on resume. Rest you can call it in onCreateView. Or you can even choose to call it in on start.






share|improve this answer






















  • I tried volley but got same result.
    – Anshul Tyagi
    Mar 7 '16 at 1:31










  • @AnshulTyagi Is your volley instance is singleton ? If not, it's behaving same and executing every call concurrently, make it singleton.
    – UMESH0492
    Mar 7 '16 at 7:39







  • 1




    I would highly recommend retrofit over volley. You have a lot more freedom.
    – Jared Burrows
    Mar 7 '16 at 8:06










  • @JaredBurrows where will I execute them? In onResume() of fragments?
    – Anshul Tyagi
    Mar 7 '16 at 10:09










  • @AnshulTyagi don't do more work in onResume, if not required . As there are lots of child fragment you have used, which are calling asynctask concurrently doing so causing system to suspend the threads to avoid freezing .
    – UMESH0492
    Mar 7 '16 at 11:01














up vote
1
down vote













Firstly i would recommend you to use any network library can be volley or retrofit. As they are more efficient and they will handle the call in background and parallely without using AsyncTask.



The way you are trying is most sophisticated, as are you calling concurrently.



If it's required, then only make network call on resume. Rest you can call it in onCreateView. Or you can even choose to call it in on start.






share|improve this answer






















  • I tried volley but got same result.
    – Anshul Tyagi
    Mar 7 '16 at 1:31










  • @AnshulTyagi Is your volley instance is singleton ? If not, it's behaving same and executing every call concurrently, make it singleton.
    – UMESH0492
    Mar 7 '16 at 7:39







  • 1




    I would highly recommend retrofit over volley. You have a lot more freedom.
    – Jared Burrows
    Mar 7 '16 at 8:06










  • @JaredBurrows where will I execute them? In onResume() of fragments?
    – Anshul Tyagi
    Mar 7 '16 at 10:09










  • @AnshulTyagi don't do more work in onResume, if not required . As there are lots of child fragment you have used, which are calling asynctask concurrently doing so causing system to suspend the threads to avoid freezing .
    – UMESH0492
    Mar 7 '16 at 11:01












up vote
1
down vote










up vote
1
down vote









Firstly i would recommend you to use any network library can be volley or retrofit. As they are more efficient and they will handle the call in background and parallely without using AsyncTask.



The way you are trying is most sophisticated, as are you calling concurrently.



If it's required, then only make network call on resume. Rest you can call it in onCreateView. Or you can even choose to call it in on start.






share|improve this answer














Firstly i would recommend you to use any network library can be volley or retrofit. As they are more efficient and they will handle the call in background and parallely without using AsyncTask.



The way you are trying is most sophisticated, as are you calling concurrently.



If it's required, then only make network call on resume. Rest you can call it in onCreateView. Or you can even choose to call it in on start.







share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 7 '16 at 7:42

























answered Mar 6 '16 at 20:20









UMESH0492

1,1851327




1,1851327











  • I tried volley but got same result.
    – Anshul Tyagi
    Mar 7 '16 at 1:31










  • @AnshulTyagi Is your volley instance is singleton ? If not, it's behaving same and executing every call concurrently, make it singleton.
    – UMESH0492
    Mar 7 '16 at 7:39







  • 1




    I would highly recommend retrofit over volley. You have a lot more freedom.
    – Jared Burrows
    Mar 7 '16 at 8:06










  • @JaredBurrows where will I execute them? In onResume() of fragments?
    – Anshul Tyagi
    Mar 7 '16 at 10:09










  • @AnshulTyagi don't do more work in onResume, if not required . As there are lots of child fragment you have used, which are calling asynctask concurrently doing so causing system to suspend the threads to avoid freezing .
    – UMESH0492
    Mar 7 '16 at 11:01
















  • I tried volley but got same result.
    – Anshul Tyagi
    Mar 7 '16 at 1:31










  • @AnshulTyagi Is your volley instance is singleton ? If not, it's behaving same and executing every call concurrently, make it singleton.
    – UMESH0492
    Mar 7 '16 at 7:39







  • 1




    I would highly recommend retrofit over volley. You have a lot more freedom.
    – Jared Burrows
    Mar 7 '16 at 8:06










  • @JaredBurrows where will I execute them? In onResume() of fragments?
    – Anshul Tyagi
    Mar 7 '16 at 10:09










  • @AnshulTyagi don't do more work in onResume, if not required . As there are lots of child fragment you have used, which are calling asynctask concurrently doing so causing system to suspend the threads to avoid freezing .
    – UMESH0492
    Mar 7 '16 at 11:01















I tried volley but got same result.
– Anshul Tyagi
Mar 7 '16 at 1:31




I tried volley but got same result.
– Anshul Tyagi
Mar 7 '16 at 1:31












@AnshulTyagi Is your volley instance is singleton ? If not, it's behaving same and executing every call concurrently, make it singleton.
– UMESH0492
Mar 7 '16 at 7:39





@AnshulTyagi Is your volley instance is singleton ? If not, it's behaving same and executing every call concurrently, make it singleton.
– UMESH0492
Mar 7 '16 at 7:39





1




1




I would highly recommend retrofit over volley. You have a lot more freedom.
– Jared Burrows
Mar 7 '16 at 8:06




I would highly recommend retrofit over volley. You have a lot more freedom.
– Jared Burrows
Mar 7 '16 at 8:06












@JaredBurrows where will I execute them? In onResume() of fragments?
– Anshul Tyagi
Mar 7 '16 at 10:09




@JaredBurrows where will I execute them? In onResume() of fragments?
– Anshul Tyagi
Mar 7 '16 at 10:09












@AnshulTyagi don't do more work in onResume, if not required . As there are lots of child fragment you have used, which are calling asynctask concurrently doing so causing system to suspend the threads to avoid freezing .
– UMESH0492
Mar 7 '16 at 11:01




@AnshulTyagi don't do more work in onResume, if not required . As there are lots of child fragment you have used, which are calling asynctask concurrently doing so causing system to suspend the threads to avoid freezing .
– UMESH0492
Mar 7 '16 at 11:01










up vote
0
down vote













Don't do heavy operation within activities or fragments, or every time you modify the user interface you will have to manage problems (with async task too).



You can use asynch task or library such as volley, but with services. A good tutorial is here.






share|improve this answer




















  • You mean I need to hit each service in each fragment by using a background service?
    – Anshul Tyagi
    Mar 7 '16 at 10:18










  • I mean is better put I/O and network code in a service and then handle it from fragment and activity through intent and message. This approach separate activity lifecycle from network operations.
    – xcesco
    Mar 7 '16 at 11:53










  • You added a link which tells How to use Service not how we manage multiple asynctasks of different fragments by using a Single Service class.
    – Anshul Tyagi
    Mar 8 '16 at 5:31














up vote
0
down vote













Don't do heavy operation within activities or fragments, or every time you modify the user interface you will have to manage problems (with async task too).



You can use asynch task or library such as volley, but with services. A good tutorial is here.






share|improve this answer




















  • You mean I need to hit each service in each fragment by using a background service?
    – Anshul Tyagi
    Mar 7 '16 at 10:18










  • I mean is better put I/O and network code in a service and then handle it from fragment and activity through intent and message. This approach separate activity lifecycle from network operations.
    – xcesco
    Mar 7 '16 at 11:53










  • You added a link which tells How to use Service not how we manage multiple asynctasks of different fragments by using a Single Service class.
    – Anshul Tyagi
    Mar 8 '16 at 5:31












up vote
0
down vote










up vote
0
down vote









Don't do heavy operation within activities or fragments, or every time you modify the user interface you will have to manage problems (with async task too).



You can use asynch task or library such as volley, but with services. A good tutorial is here.






share|improve this answer












Don't do heavy operation within activities or fragments, or every time you modify the user interface you will have to manage problems (with async task too).



You can use asynch task or library such as volley, but with services. A good tutorial is here.







share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 7 '16 at 8:24









xcesco

1,9151533




1,9151533











  • You mean I need to hit each service in each fragment by using a background service?
    – Anshul Tyagi
    Mar 7 '16 at 10:18










  • I mean is better put I/O and network code in a service and then handle it from fragment and activity through intent and message. This approach separate activity lifecycle from network operations.
    – xcesco
    Mar 7 '16 at 11:53










  • You added a link which tells How to use Service not how we manage multiple asynctasks of different fragments by using a Single Service class.
    – Anshul Tyagi
    Mar 8 '16 at 5:31
















  • You mean I need to hit each service in each fragment by using a background service?
    – Anshul Tyagi
    Mar 7 '16 at 10:18










  • I mean is better put I/O and network code in a service and then handle it from fragment and activity through intent and message. This approach separate activity lifecycle from network operations.
    – xcesco
    Mar 7 '16 at 11:53










  • You added a link which tells How to use Service not how we manage multiple asynctasks of different fragments by using a Single Service class.
    – Anshul Tyagi
    Mar 8 '16 at 5:31















You mean I need to hit each service in each fragment by using a background service?
– Anshul Tyagi
Mar 7 '16 at 10:18




You mean I need to hit each service in each fragment by using a background service?
– Anshul Tyagi
Mar 7 '16 at 10:18












I mean is better put I/O and network code in a service and then handle it from fragment and activity through intent and message. This approach separate activity lifecycle from network operations.
– xcesco
Mar 7 '16 at 11:53




I mean is better put I/O and network code in a service and then handle it from fragment and activity through intent and message. This approach separate activity lifecycle from network operations.
– xcesco
Mar 7 '16 at 11:53












You added a link which tells How to use Service not how we manage multiple asynctasks of different fragments by using a Single Service class.
– Anshul Tyagi
Mar 8 '16 at 5:31




You added a link which tells How to use Service not how we manage multiple asynctasks of different fragments by using a Single Service class.
– Anshul Tyagi
Mar 8 '16 at 5:31

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f35054425%2fsuspending-threads-while-running-multiple-asynctasks-in-nested-fragments-and-it%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to how show current date and time by default on contact form 7 in WordPress without taking input from user in datetimepicker

Syphilis

Darth Vader #20