I have a ListView in Activity1. OnItemClick, I’m navigating to another activity Activity2 where I have some database code.
Now the problem is fetching data from DB is taking some time, so while navigating from Activity1 to Activity2, for few seconds blank screen appears.
To overcome this, I tried ProgressDialog but ProgressDialog is not appearing at all.
Code snippet from Activity 2:
public class Activity2 extends Activity implements Runnable {
@Override
public void onCreate(Bundle savedInstanceState) {
Thread thread = new Thread();
thread.start();
run();
}
@Override
public void run() {
plansDesc = dbMgr.chkRecord(
"SELECT Description FROM SubPlan where Title='" + subTitle
+ "'", "Description");
ProgressDialog progDailog = ProgressDialog.show(
SubPlanDescActivity.this, "Plan Information", "Loading...",
true);
try {
if (plansDesc != "") {
tvDesc.setText(Html.fromHtml(plansDesc));
} else {
tvDesc.setText(Html
.fromHtml("<b>No Information Available...</b>"));
}
} catch (Exception e) {
}
handler.sendEmptyMessage(0);
progDailog.dismiss();
}
private Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
}
};
ANY HELP APPRECIATED.
Try AsyncTask instead of thread
See the below code
Now create class