-4

I am working on application where we are creating Activity B from Activity A. From Activity B, we are creating Activity C where we would like to return image and text back to Activity A.

Checked in Google but not get answer that I am looking for. Can you advice how this can be possible?

Thanks in advance for your help.

Update : First of all thnx for your answers. Let me explain my requirement more clearly.

Under Activity A, through Intent we open Gallery and choose Image. By defining startActivityForResult in this activity, we capture image that user picked and created new Intent (Activity B) where we took all parameters through putExtra function. We displayed user picked image here and allow user to edit image and put text. Now what we are looking for is to display Edited Image and text in already created Activity A. The data addition will be through List view were already few List view rows are present.

Hope we are more clear in our requirement now.

Thanks in advance for your help.

Update (showing some code as well)

Below code I applied in Activity A

  Intent intent = new Intent(Intent.ACTION_PICK,               
   android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                intent.setType("image/*");
                startActivityForResult(Intent.createChooser(intent, "Select File"), SELECT_FILE);

Results are available in Activity A through startActivityForResult as follows

 if (requestCode == SELECT_FILE) {
            Uri selectedImageUri = data.getData();
            String[] projection =   
   {MediaStore.MediaColumns.DATA};Log.i("User_Chat_Page",  
   "projection="+selectedImageUri);
    Cursor cursor =managedQuery(selectedImageUri,projection,null,null,null);
    int column_index =  
     cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATA);
     cursor.moveToFirst();

     String selectedImagePath = cursor.getString(column_index);
     image_name = selectedImagePath;
     Bitmap bm;
     BitmapFactory.Options options = new BitmapFactory.Options();
     options.inJustDecodeBounds = true;
     BitmapFactory.decodeFile(selectedImagePath, options);
     final int REQUIRED_SIZE = 200;
     int scale = 1;
     while (options.outWidth / scale / 2 >= REQUIRED_SIZE
     && options.outHeight / scale / 2 >= REQUIRED_SIZE)
               scale *= 2;
     options.inSampleSize = scale;
     options.inJustDecodeBounds = false;
     bm = BitmapFactory.decodeFile(selectedImagePath, options);
     Intent edit_image_intent = new Intent(ctx, 
     DrawOnBitmapActivity.class);
     edit_image_intent.putExtra("selected_img_path", 
     selectedImagePath);
     edit_image_intent.putExtra("selected_imguri", selectedImageUri);
     edit_image_intent.putExtra("message_source", "to");
     edit_image_intent.setData(selectedImageUri);
     ctx.startActivity(edit_image_intent);
                        }

The image is displayed in Activity B (intent : edit_image_intent)were user edit image and put text.

My query is how we can able to bring the edit image and text in Activity-A. The display is required in List view as view rows are already displayed in Actiity-A (Eg. as in chat code)

Subhash
  • 27
  • 6
  • Try If it hepls. Use a single instance class and keep those image and text from Activity C and fetch those in Activity A. – Raghavendra Dec 18 '15 at 05:14
  • Shared preference will work or from activity 3 start intent with extra to activity 1, be care full there may be possible issues in implementing method 2, another method is a single instance class – Sree Dec 18 '15 at 05:14
  • Possible duplicate of [How do I pass data between activities on Android?](http://stackoverflow.com/questions/2091465/how-do-i-pass-data-between-activities-on-android) – Madhukar Hebbar Dec 18 '15 at 05:18

2 Answers2

2

I would suggest you do it via database or shared preference. Intents will be a bad choice for you

Mightian
  • 6,853
  • 3
  • 37
  • 50
0

If you want to avoid database or shared preferences than you can cascade onActivityResult() method in activities:

ActivityA -> startActivityForResult(AcivitityB)

             ActivityB -> startActivityForResult(ActivityC)

                          add text and image(url) here to result
                          setResult()
                          finish activity

             ActivityB.onActivityResult()
             get data from AcitivityC result

             setResult() with data received

ActivityA.onActivityResult()
get data from result
Abdullah
  • 6,605
  • 6
  • 23
  • 39