If I were you, I would save all your UI updates in your main Activity class. You simply get your DBWork class to return the text you want to display to your Activity . So something like:
public class Main extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); TextView tv = (TextView) view.findViewById(R.id.TextView01); DBWork db = new DBWork("192.168.2.14:8080/DH/DPost";, "test_db"); tv.setText(db.getText()); } }
Then your db class:
public class DBWork{ ... public String getText(){
Please note that any database operations that you perform during onCreate should be as fast as possible, as they work in the user interface thread. If you intend to make lengthy database queries, you should use AsyncTask or create a new Thread and use Handler to update the user interface.
source share