在我的Android应用中,我们有自动填充文本视图。我们从数据库中获取显示到自动完成文本视图的值(使用Php脚本访问的mysql)。数据库返回大约45个值。 在我的Android应用程序中,我有一个asynctask读取值和onPostexecute我将值绑定到自动完成区域textview。
我的问题是当我在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 :(得分:0)
当您调试应用程序时,系统不仅会将您带到特定方法,还会让您前往所使用的每种方法以完成特定方法。对于您来说,您是否想要一次又一次按F8
或按F9
并跳转到另一个断点,这是您的选择。在调试过程中手机冻结的原因是
因此,您应该避免在长循环或线程下放置断点,当然也要避免在需要大量计算的任务中放置断点。 如果你想检查值,你应该去
日志类似于System.out.println();
,即它允许您查看 AndroidLogcat 或 AndroidMonitor 中的响应(如果您使用的是AS Version&lt; 3)
另外 如果你在模拟器上进行测试,这是一个非常糟糕的主意。你需要有一个非常好的桌面。像16Gigs的RAM,i7处理器,如果是Linux或Windows。仿真器很慢。使用真正的手机。您的手机不会像模拟器那样冻结。