0

Using Fragments as I need TabLayout . And inside one Fragment I am using an AsyncTask. But inside this class I am unable to use Log.w() , ie there is no error in IDE , but in the Android Monitor, I cannot see anything. Here is the code , and what might be causing this?

    public class FeedsFragment extends Fragment
{
    private static String URL_FEED;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        View rootView = inflater.inflate(R.layout.feeds, container, false);

        SharedPreferences pref = this.getActivity().getSharedPreferences("ActivitySession", Context.MODE_PRIVATE);

        Log.w("EduKnow:::",""+pref.getString("MOB",""));


        URL_FEED = "http://api.eduknow.info/mobile/feeds/buttercup/"+pref.getString("MOB","");

        new FeedTask().execute(URL_FEED);
        return rootView;
    }

    private class FeedTask extends AsyncTask<String, String, String> {

        ProgressDialog progress1;





        @Override
        protected void onPreExecute() {
            progress1 = new ProgressDialog(getActivity(),ProgressDialog.STYLE_SPINNER);
            progress1.setMessage("Updating Feeds");
            progress1.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
            progress1.setIndeterminate(true);
        }

        protected String doInBackground(String... urls) {
            String result1 = "";
            try {

                HttpGet httpGet1 = new HttpGet(urls[0]);
                HttpClient client1 = new DefaultHttpClient();

                HttpResponse response1 = client1.execute(httpGet1);

                int statusCode = response1.getStatusLine().getStatusCode();

                if (statusCode == 200) {
                    InputStream inputStream1 = response1.getEntity().getContent();
                    BufferedReader reader1 = new BufferedReader
                            (new InputStreamReader(inputStream1));
                    String line1;
                    while ((line1 = reader1.readLine()) != null) {
                        result1 += line1;
                    }
                }

            } catch (ClientProtocolException e) {

            } catch (IOException e) {

            }
            //Log.w("PREMIERE::::",result);
            Log.w("EduKnow:::",""+result1);
            return result1;
        }

        protected void onPostExecute(String jsonString) {
            // Dismiss ProgressBar
            showData(jsonString);
            progress1.dismiss();
        }
    }
    private void showData(String jsonString) {

        try
        {

            Gson gson = new Gson();
            JsonParser parser = new JsonParser();
            JsonArray jArray = parser.parse(jsonString).getAsJsonArray();

            ArrayList<FeedPojo> feeds = new ArrayList<FeedPojo>();

            for(JsonElement obj : jArray )
            {
                FeedPojo cse = gson.fromJson( obj , FeedPojo.class);
                feeds.add(cse);
            }

            for(FeedPojo fx :feeds)
            {
                 Log.w("EduKnow:::",""+fx.getFeedTitle());
            }


            //mAdapterPop = new CustomAdapter(posts_popular);
            //mAdapterPop.notifyDataSetChanged();




            //mRecyclerViewPop.setAdapter(mAdapterPop);

        }
        catch (Exception e)
        {
            Snackbar.make(getActivity().findViewById(android.R.id.content), "Check data connection", Snackbar.LENGTH_LONG).show();
            e.printStackTrace();
        }

    }
}
OBX
  • 6,044
  • 7
  • 33
  • 77
  • 1
    Is the logging level set to 'verbose' ? – Mark Dec 26 '15 at 18:24
  • I havent set it , the thing is , I am able to log in other activities ! – OBX Dec 26 '15 at 18:27
  • Seems strange, the only difference is that do in back ground runs in a different thread than activities/fragments. I assume the async task is completing and returning a result. I've only ever experienced this problem when I used a service in a different process which obviously this is not the case here. This post may help: http://stackoverflow.com/a/28517794/4252352 – Mark Dec 26 '15 at 18:32

0 Answers0