I am selecting an image from gallery in first activity and with the selected image i am going to second activity.Here i want to display an alert dialog showing the message "Loading...." after user selects an image from gallery and before going to the next activity,please help me.
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
 import android.os.CountDownTimer;
import android.provider.MediaStore;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.Toast;
 public class LauncherActivity extends Activity 
  {
   private static int RESULT_LOAD_IMAGE = 1;
 ImageButton gallery;
 ImageView gallery_image;
 int height = 500;
 Intent i;
 Intent intent;
int width = 380;
@SuppressWarnings("deprecation")
protected void onCreate(Bundle paramBundle)
{
super.onCreate(paramBundle);
setContentView(R.layout.launcher);
gallery = (ImageButton)findViewById(R.id.select_photo);
camera = (ImageButton)findViewById(R.id.take_photo);
free_apps = (ImageButton)findViewById(R.id.free_apps);
gallery.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        Intent gallery_intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
        startActivityForResult(gallery_intent, RESULT_LOAD_IMAGE);
    }
});
     }
      protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  super.onActivityResult(requestCode, resultCode, data);
  if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data)    {
      Uri selectedImage = data.getData();
      String[] filePathColumn = { MediaStore.Images.Media.DATA };
      Cursor cursor = getContentResolver().query(selectedImage,
              filePathColumn, null, null, null);
      cursor.moveToFirst();
      int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
      String picturePath = cursor.getString(columnIndex);
      cursor.close();
        final AlertDialog.Builder dialog = new AlertDialog.Builder(this);
        dialog.setMessage("Loading....");
     final AlertDialog alert = dialog.create();
     alert.show();
    new CountDownTimer(5000, 1000) {
  @Override
  public void onTick(long millisUntilFinished) {
      // TODO Auto-generated method stub
  }
  @Override
  public void onFinish() {
      // TODO Auto-generated method stub
       alert.dismiss();
     }
   }.start();
      Bitmap bitmap_for_gallery =              Bitmap.createScaledBitmap(BitmapFactory.decodeFile(picturePath), width, height, true);
      ByteArrayOutputStream stream = new ByteArrayOutputStream();
      bitmap_for_gallery.compress(Bitmap.CompressFormat.PNG, 100, stream);
      byte[] byteArray = stream.toByteArray();
      Intent intent = new Intent(LauncherActivity.this, MainActivity.class);
      intent.putExtra("image", byteArray);
      startActivity(intent);
       }
     }
   }
 
    