0

Here is my code i am getting the issue as handler class should be static.. The issue is while i am getting the result it takes too much time to view after completing the loading bar ..

 progressDialog = ProgressDialog.show(MainActivity.this, "", 
                 "Loading. Please wait...", true);

        new Thread() 
        {
            public void run() 
            {
             try
                {
                URL userurl = new URL("https://api./////");
                BufferedReader in = new BufferedReader(new InputStreamReader(userurl.openStream()));
                String inputLine;
                String strJson1 = "";
                while ((inputLine = in.readLine()) != null) 
                {
                    strJson1 += inputLine;
                }



                jsonobj = new JSONObject(strJson1);

            questionarray = jsonobj.getJSONArray("items");



                } catch (MalformedURLException tagobject) {
                    // TODO Auto-generated catch block
                    tagobject.printStackTrace();
                } catch (IOException tagobject) {
                    // TODO Auto-generated catch block
                    tagobject.printStackTrace();
                }catch (JSONException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                    }
     handler.sendEmptyMessage(0);
        progressDialog.dismiss();
    }
}.start();
handler = new Handler() {
@Override
public void handleMessage(Message msg) {
    try
    {
        for (int i = 0;  i<questionarray.length(); i++) {

            questionobj = questionarray.getJSONObject(i);                   
            uploadquestions = new HashMap<String, Object>();

            uploadquestions.put("question_id",questionobj.get("question_id"));}
    catch(Exception e)
{
System.out.println(e);
}

}
};

could anybody help me..

  • This is very confusing. Your question subject does not match the text and in any case, it's hard to see exactly what your question is. – Simon Feb 21 '13 at 07:54
  • Please see this http://www.androiddesignpatterns.com/2013/01/inner-class-handler-memory-leak.html and this https://groups.google.com/forum/?fromgroups=#!msg/android-developers/1aPZXZG6kWk/lIYDavGYn5UJ – Rajesh Feb 21 '13 at 08:01
  • @Rajesh do you have any better suggestion –  Feb 21 '13 at 08:27
  • If you go through the given links, you will find your solution, not just a "better suggestion". – Rajesh Feb 21 '13 at 08:28
  • @thanks..but in my code the progress is not even displaying its shows white screen the its load the data –  Feb 21 '13 at 08:32

0 Answers0