1

I am selecting an image from gallery and moving to MainActivity to display the image selected.I need to display a progress dialog over gallery screen only after I click on an image from gallery and display it for 3 seconds and then i should move to MainActivity to display the selected image.I am getting the dialog here over first activity not over the gallery screen.How should i achieve this?I have spent so much time to solve this.But i did not get it.Please help me .I am providing my updated sample code here.

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;




public class LauncherActivity extends Activity 
{
 private static int RESULT_LOAD_IMAGE = 2;
 ImageButton gallery;
 Bitmap bitmap_for_gallery;
 String picturePath;
 ProgressDialog dialog;;
 Uri selectedImage;

 protected void onCreate(Bundle paramBundle)
{
super.onCreate(paramBundle);
setContentView(R.layout.launcher);
gallery = (ImageButton)findViewById(R.id.select_photo);

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, final Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
      if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) {

      AsyncTask<String, Void, String> updateTask = new AsyncTask<String, Void, String>(){


            @Override

            protected void onPreExecute() {
              selectedImage = data.getData();
                dialog = new ProgressDialog(LauncherActivity.this);
                dialog.setMessage("Loading...");
                dialog.show();
            }
            protected String doInBackground(String... params) {
                // TODO Auto-generated method stub
                String[] filePathColumn = { MediaStore.Images.Media.DATA };
                  Cursor cursor = getContentResolver().query(selectedImage,filePathColumn, null, null, null);
                  cursor.moveToFirst();
                  int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
                   picturePath = cursor.getString(columnIndex);
                  cursor.close();
                return null;
            }
            protected void onPostExecute(String result) {
                Intent intent = new Intent(LauncherActivity.this, MainActivity.class);
                intent.putExtra("path", picturePath); 
                startActivity(intent);
                dialog.dismiss();
            }

        };

        updateTask.execute();
  }
 }
}

and my MainActivity is

 import android.app.Activity;
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
 import android.os.Bundle;
 import android.widget.FrameLayout;
 import android.widget.ImageView;
 import android.widget.RelativeLayout.LayoutParams;


 public class MainActivity extends Activity {
 ImageView background;
 Bitmap transfered;
  FrameLayout.LayoutParams layoutParams;

@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
 background=(ImageView)findViewById(R.id.imageView1);

 layoutParams=new FrameLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT);
 Bundle extras = getIntent().getExtras();

    String picturePath=extras.getString("path");
     transfered=BitmapFactory.decodeFile(picturePath);  
 background.setImageBitmap(transfered); 
 background.setAdjustViewBounds(true);
 background.setLayoutParams(layoutParams);
 }

}
Itisme
  • 53
  • 6
  • use asynchronous task fun(),might help you. – prakash Jun 05 '14 at 13:01
  • I have used it.But i am getting dialog over first activity because dialog is created using first activity context.which context should i use to get the dialog over gallery screen? – Itisme Jun 05 '14 at 13:03
  • use this link: http://stackoverflow.com/questions/14250989/how-to-use-asynctask-correctly-android run that your cursor in background ,after dismiss the dialog in postexecute and then start intent next line to the dialog dismiss – prakash Jun 05 '14 at 13:10
  • there dialog is called based on the context of the activity.then dialog will be displayed over the activity but not over the gallery screen – Itisme Jun 06 '14 at 04:21
  • dialog creates only with in your activity,so far my knowledge out side your application is not possible. – prakash Jun 06 '14 at 04:27
  • but it is possible.Thanks for your answers.If you have any thought,please post to me. – Itisme Jun 06 '14 at 04:30
  • post your asynchronous task fun. – prakash Jun 06 '14 at 04:32
  • please check the first activity.I have modified . – Itisme Jun 06 '14 at 04:38

0 Answers0