I read in some links that i need to convert my runOnUiThread to AsyncTask: Android: RunOnUiThread vs AsyncTask
But I am unable to get it done. I am implementing an AutoCompleteText which takes query from a database.
My runOnUiThread along with the new thread (it compiles):
new Thread(new Runnable() {
public void run() {
final DataBaseHelper dbHelper = new DataBaseHelper(ActivityName.this);
dbHelper.openDataBase();
item_list = dbHelper.getAllItemNames();
ActivityName.this.runOnUiThread(new Runnable() {
public void run() {
ArrayAdapter<String> sAdapter = new ArrayAdapter<String>(
ActivityName.this,
android.R.layout.simple_dropdown_item_1line,
item_list);
itemNameAct = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView_item_name);
itemNameAct.setAdapter(sAdapter);
}
});
}
}).start();
I put the worker thread part in doInBackground and the runOnUiThread part of code in onPostExecute but it crashes on launch.