androidtabsactivitygroup

Second activity is not being displayed using Activitygroup with Tab


In my app, I' using Tab. There are three tabs. In which 3rd tab is Activity group which has two activities. In first activity, there are two options for user. User can choose image from camera or from gallery. After selecting an image, user should move to child activity, which will display selected image in that activity. Below is my code...

public class GalleryPic extends Activity {

    private static final int TAKE_PICTURE = 0;
    private static final int REQUEST_ID = 1;
    private static final int HALF = 2;
    private Uri mUri;
    private Bitmap mPhoto;
    ImageView ivGallery, ivCamera;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.gallery_pic);
        ivGallery = (ImageView)findViewById(R.id.gallery);
        ivCamera = (ImageView)findViewById(R.id.snap);

        ivGallery.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setAction(Intent.ACTION_GET_CONTENT);
                intent.addCategory(Intent.CATEGORY_OPENABLE);
                intent.setType("image/*");
                Intent in = new Intent(getParent(), GalleryPic_Second.class);
                TabGroupActivity parent = (TabGroupActivity) getParent();
                parent.startChildActivity("ArrowsActivity", in);
                startActivityForResult(intent, REQUEST_ID);

            }
        });

        ivCamera.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent i = new Intent("android.media.action.IMAGE_CAPTURE");
                File f = new File(Environment.getExternalStorageDirectory(),  "photo.jpg");
                i.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f));
                mUri = Uri.fromFile(f);
                Intent in = new Intent(getParent(), GalleryPic_Second.class);
                TabGroupActivity parent = (TabGroupActivity) getParent();
                parent.startChildActivity("ArrowsActivity", in);
                startActivityForResult(i, TAKE_PICTURE);
            }
        });


    }




    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        switch (requestCode) {
        case TAKE_PICTURE:
            if (resultCode == Activity.RESULT_OK) 
            {
                getContentResolver().notifyChange(mUri, null);
                ContentResolver cr = getContentResolver();

                Intent previewMessage = new Intent(getParent(), GalleryPic_Second.class);

                TabGroupActivity parentActivity = (TabGroupActivity) getParent();
                parentActivity.startChildActivity("ArrowsActivity", previewMessage);

                try 
                {
                    mPhoto = android.provider.MediaStore.Images.Media.getBitmap(cr, mUri);
                    Intent in = new Intent(getParent(), GalleryPic_Second.class);
                    GalleryPic_Second.bmp = mPhoto;
                    TabGroupActivity parent = (TabGroupActivity) getParent();
                    parentActivity.startChildActivity("ArrowsActivity", in);

                }

                catch (Exception e) 
                {
                    Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
                }


            }


            break;
        case REQUEST_ID :
            InputStream stream = null;
             if (resultCode == Activity.RESULT_OK) {

                 try
                 {
                    stream = getContentResolver().openInputStream(data.getData());
                    Bitmap original = BitmapFactory.decodeStream(stream);
                    Intent in = new Intent(getParent(), GalleryPic_Second.class);
                    GalleryPic_Second.bmp = Bitmap.createScaledBitmap(original, original.getWidth()/HALF, original.getHeight()/HALF, true);
                    TabGroupActivity parent = (TabGroupActivity) getParent();
                    parent.startChildActivity("ArrowsActivity", in);                           
                 }

                 catch (Exception e) 
                 {
                    e.printStackTrace();
                 }
                if (stream != null) {
                    try {
                        stream.close();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }



             }


        }
    }


    @Override
    public void onBackPressed() {
    // this.getParent().onBackPressed();
         TabViewLayout parentTab = (TabViewLayout) this.getParent();
         parentTab.switchTabBar(1);

    }

  } 

What I'm facing here is, I'm not getting selected image in child activity group. I've searched about it and came to this solution... OnActivityResult is not working in TabActivityGroup? But I'm not getting the explanation which is given in this link. What needs to be done?


Solution

  • Hi put your on ActivityResult code in GroupActivity means in the parent because it return value to it's parent not a child.

     public void onActivityResult(int requestCode, int resultCode, Intent data) {
            super.onActivityResult(requestCode, resultCode, data);
            switch (requestCode) {
    }
    }
    

    above code put in Activity group .I hope it will work for you because it is working for me best of luck :-).