2017-11-05 7 views
0

私のAndroidアプリでは、オートコンプリートのテキストビューがあります。データベースから自動完成テキストビューに表示される値を取得します(phpスクリプトを使用してmysqlにアクセスします)。データベースは約45の値を返します。 私のアンドロイドアプリでは、オートコンプリートエリアのテキストビューに値をバインドする値とonPostexecute imを読み込むasynctaskがあります。デバッグなしで実行中に画面がフリーズする

私の問題は、デバッグし、私のonPostExecuteまたはどこかのアプリケーションが完全に動作するブレークポイントを設定するときです。私は、デバッグを行わずに画面をフリーズし、何もしません。私はここで何が間違っているのかわからない。誰でも助けて!

マイASynctask:あなたはあなたのアプリケーションをデバッグするとき

public class AsyncGetCityList extends AsyncTask<String, Void, String> 
    { 
    String orderdetailsurl = "URL for my DB"; 

    @Override 
    protected String doInBackground(String... params) { 

     String method = params[0]; 
     if (method.equals("getCityList")) { 
      //String mobilenumber = params[1]; 
      String result = null; 

      try { 
       URL reseturl = new URL(orderdetailsurl); 
       HttpURLConnection loginconnection = (HttpURLConnection) reseturl.openConnection(); 
       loginconnection.setRequestMethod("POST"); 
       loginconnection.setDoOutput(true); 
       loginconnection.setDoInput(true); 
       OutputStream loginos = loginconnection.getOutputStream(); 
       BufferedWriter loginbw = new BufferedWriter(new OutputStreamWriter(loginos, "UTF-8")); 
       // loginbw.write(data); 
       loginbw.flush(); 
       loginbw.close(); 

       InputStream loginis = loginconnection.getInputStream(); 
       BufferedReader loginbr = new BufferedReader(new InputStreamReader(loginis, "iso-8859-1")); 
       String response = ""; 
       StringBuilder sb = new StringBuilder(); 
       String line = ""; 
       while ((line = loginbr.readLine()) != null) { 
        sb.append(line + "\n"); 
       } 
       result = sb.toString(); 
      } catch (Exception e) { 
       // Oops 
      } finally { 

      } 
      return result; 
     } 
     return null; 
    } 

    @Override 
    protected void onPostExecute(String result) 
    { 
     android.os.Debug.waitForDebugger(); 
     if (result == null) { 
      final android.app.AlertDialog.Builder alertdialog = new android.app.AlertDialog.Builder(MainActivity.this); 
      alertdialog.setMessage("Please check your Internet Connection!!!"); 
      alertdialog.setPositiveButton("OK", new DialogInterface.OnClickListener() { 
       @Override 
       public void onClick(DialogInterface dialog, int which) { 

        Intent intent = getIntent(); 
        finish(); 
        startActivity(intent); 
       } 
      }); 

      alertdialog.setTitle("Warning").create(); 
      alertdialog.show(); 
     } else { 
      getCityJSON = result; 
      ShowCityList(); 
      //progressView.dismiss(); 

     } 
    } 
} 

protected void ShowCityList() { 
    try 
    { 
     JSONObject jsonObj = new JSONObject(getCityJSON); 
     cityJSONArray = jsonObj.getJSONArray(TAG_RESULT); 
     areas=new String[cityJSONArray.length()]; 
     for (int i = 0; i < cityJSONArray.length(); i++) { 
      JSONObject c = cityJSONArray.getJSONObject(i); 
      String City=c.getString(TAG_CITY); 
     areas[i]=City; 
    } 

     arrayAdapter = new ArrayAdapter<String>(
      this, android.R.layout.simple_dropdown_item_1line, areas); 
     autocompletearea.setAdapter(arrayAdapter); 

     autocompletearea.setThreshold(1); 

     autocompletearea.setOnClickListener(new View.OnClickListener() 
     { 
      @Override 
      public void onClick(View v) { 

       autocompletearea.showDropDown(); 
      } 
     }); 
     autocompletearea.setOnFocusChangeListener(new View.OnFocusChangeListener() 
     { 
      @Override 
      public void onFocusChange(View v, boolean hasFocus) 
      { 
       autocompletearea.showDropDown(); 
      } 
     }); 


     autocompletearea.setOnItemClickListener(new AdapterView.OnItemClickListener() { 
      @Override 
      public void onItemClick(AdapterView<?> parent, View view, int position, long id) { 
       InputMethodManager in = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); 
       in.hideSoftInputFromWindow(view.getApplicationWindowToken(), 0); 
       String selection = (String) parent.getItemAtPosition(position); 
       for (int i = 0; i < areas.length; i++) { 
        if (areas[i].equals(selection)) { 
         pos = i; 
         break; 
        } 
       } 

       System.out.println("Position " + pos); //check it now in Logcat 

       city=autocompletearea.getText().toString(); 

       SharedPreferences.Editor editor = getPreferences(0).edit(); 

       session.setcityselectedpreference(MainActivity.this,"cityselected","1"); 
       int selectedPosition = parent.getSelectedItemPosition(); 
       editor.putInt("spinnerSelection", pos); 
       editor.commit(); 

      } 
     }); 

     SharedPreferences prefs = getPreferences(0); 
     String cityselectedsession=session.getcityselectedPreference(this,"cityselected"); 
     if(cityselectedsession.equals("")) 
     { 
      autocompletearea.setText(""); 
     } 
     else if(cityselectedsession.equals("1")) { 
      autocompletearea.setText(areas[prefs.getInt("spinnerSelection", 0)]); 
     } 
    } catch (JSONException e) { 
     e.printStackTrace(); 
    } 

} 

答えて

0

、システムだけではなく、特定のメソッドが表示されますが、あなたは特定のメソッドを終了するために使用されているすべての単一の方法に旅行になります。クロウズのうち、F8を何度も押すか、F9を押して別のブレークポイントにジャンプするかどうかはあなたの選択です。デバッグ中に携帯電話がフリーズする理由は、

  1. です。非同期タスクはスレッドのようなものです。
  2. DataBaseからデータを取得することは、お使いの携帯電話にとって簡単な作業ではありません。

したがって、長いループやスレッドの下にブレークポイントを配置しないでください。もちろん、多くの計算を必要とするタスクでは避けてください。 あなたが値を確認したい場合は、あなたがバージョンとして使用している場合、それはあなたがAndroidLogcatまたはAndroidMonitor(に応答を見ることができますIE用

Logs

ログがSystem.out.println();に似て行く必要があります< 3)

エミュレータでテストしていた場合、非常に悪い考えです。あなたは本当に良いデスクトップが必要です。 LinuxやWindowsの場合は、16GigsのRAM、i7プロセッサのように。エミュレータは遅いです。実際の電話を使用してください。あなたのエミュレータと同じくらいあなたの電話はフリーズしません。

+0

返信いただきありがとうございます!あなたが言ったように、私はF9を与えて別のスレッドにジャンプしてデバッグしています。しかし、私の画面は通常の実行中に凍って、私はエミュレータでアプリケーションがフリーズします。あなたが私のアプリを実行するだけであればいいのですが、私の主張を明確にしたいと思っています:( – RKM

+0

ああ、あなたはエミュレータでテストしていたのですが、それは本当に良いデスクトップです。 、i7プロセッサエミュレータが遅い実際の電話を使用するあなたのエミュレータと同じくらい凍結しない – Dennis

+0

私の電話機を接続してアプリを実行しようとしたが、同じことが起こった(画面がフリーズする)。可能なすべての行に示唆したようにログを書き込もうとしましたが、それは私のonPostExecuteまで続きますが、onPostExecuteのif elseループ内のログステートメントは出力されませんでした。 – RKM

関連する問題