Finally I fixed it with asyncTask.
public void onNewIntent(Intent intent) {
setIntent(intent);
ScanDialog = ProgressDialog.show(BorrowActivity.this,
"Scanning...", "Scanning");
try {
new DoBackgroundTask().execute();
} catch (Exception e) {
//error catch here
}
ScanDialog.dismiss();
And AsyncTask:
private class DoBackgroundTask extends AsyncTask<Integer, String, Integer> {
protected Integer doInBackground(Integer... status) {
//do something
}
protected void onProgressUpdate(String... message) {
}
protected void onPostExecute(Integer status) {
}
}