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();
}
}
}