2016-07-02 3 views
0

데이터를 사용하는 응용 프로그램을 만들고 응답을 위해 내 서버에 'GET' (안전하지는 않지만 개인 정보가 아닙니다)으로 보냅니다. 그러나, 나는 점점 계속 :Android Studio에서 '활동 유휴'가 발생하는 이유는 무엇입니까?

"Timeline: Activity_idle id: [email protected] 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("\"", ""))); 
    } 
    } 

답변

0

모든 네트워킹은 별도의 스레드에서 수행해야합니다. 나는 재촉한다 AsyncTask

+0

나는 생각했다? URL 요청을 사용할 때 다른 페이지에서 제대로 작동합니다. –

관련 문제