此Handler类应该是静态的,否则可能会发生泄漏:

时间:2013-02-21 07:48:06

标签: android class handler

这是我的代码我得到的问题因为处理程序类应该是静态的..问题是当我得到结果时,在完成加载栏后需要花费太多时间来查看..

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

}
};

任何人都可以帮助我..

0 个答案:

没有答案
相关问题