Saturday, February 18, 2012

Thread Example in Android


protected void CallThread(final String submitType) {

final ProgressDialog dialog = ViewUtils.getProgressDialog(
SaleCreatePlannerActivity.this, "Downloading...");
dialog.show();

new Thread() {
public void run() {
try {
    // Perform job
SubmitReport(submitType);
// sleep(5000);
} catch (Exception e) {
}
handler.sendEmptyMessage(0);

if (dialog != null && dialog.isShowing()) {
dialog.dismiss();
}
}
}.start();

}
    private Handler handler = new Handler() {
    @Override
    public void handleMessage(Message msg) {
    Toast.makeText(ClassName.this,"Successful ", Toast.LENGTH_SHORT).show();

    }
    };

No comments:

Post a Comment