Use the below code to perform heavy tasks.
// Your package hereimport java.util.List;import org.apache.http.NameValuePair;import android.app.Activity;import android.app.ProgressDialog;import android.content.Context;import android.os.AsyncTask;import android.view.View.OnSystemUiVisibilityChangeListener;public class AsyncRequest extends AsyncTask<String, Integer, String> { Context context; ProgressDialog pDialog; // Three Constructors public AsyncRequest(Activity a, String m, List<NameValuePair> p) { context = a; method = m; parameters = p; } public AsyncRequest(Activity a) { this.caller = (OnAsyncRequestComplete) a; context = a; } public String doInBackground(String... urls) { //Perform your task here return result; } public void onPreExecute() { pDialog = new ProgressDialog(context); pDialog.setMessage("Please wait.."); pDialog.setCancelable(false); pDialog.show(); } public void onProgressUpdate(Integer... progress) { // You can implement some progressBar and update it in this record. // setProgressPercent(progress[0]); } public void onPostExecute(String response) { if (pDialog != null && pDialog.isShowing()) { pDialog.dismiss(); } // Get the result here } protected void onCancelled(String response) { if (pDialog != null && pDialog.isShowing()) { pDialog.dismiss(); } }}