为什么我会活动闲置'在Android Studio?

时间:2016-07-02 12:03:15

标签: java android android-studio

我正在创建一个使用数据的应用,并将其作为'GET'(我知道它不安全,但它不是私人信息)发送到我的服务器以获取响应。但是,我一直在说:

"Timeline: Activity_idle id: android.os.BinderProxy@3e9ea84a time:10320512"

我的代码在这里:

         public class textDisplay3 extends AppCompatActivity {
  String code1 = "none";
String String2;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_text_display3);
    TextView text123V = (TextView) findViewById(R.id.textRVC);
    Intent intent = getIntent();
    String theText = intent.getStringExtra("textData");
    try {
        BufferedReader reader = new BufferedReader(new InputStreamReader(getAssets().open("codes.txt")));
        String line;
        while ((line = reader.readLine()) != null) {

            String[] RowData = line.split(",");
            if (RowData.length == 2 && RowData[0] == theText) {
             code1 =  RowData[1];
            }

        }

    } catch (IOException ex) {
        ex.printStackTrace();
    } finally {

    }
// Instantiate the RequestQueue.
    RequestQueue queue = Volley.newRequestQueue(this);

    String url = "https://www.mywebsite.com/file.php?code="+code1;

 // Request a string response from the provided URL.
    StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    String2 = response;
                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            Log.e("Volley Error", String.valueOf(error));
            String2 = "Error Connecting to Server for Live Weather!";
        }
    });
    // Add the request to the RequestQueue.
    queue.add(stringRequest);

    text123V.setText(Html.fromHtml(String2.replace("\"", "")));
     }
   }

1 个答案:

答案 0 :(得分:0)

所有网络必须在单独的线程中完成。我重新考虑AsyncTask