开发者

How to get ActivityGroup to get result from child activity

开发者 https://www.devze.com 2023-03-30 22:48 出处:网络
So Here\'s the basic structure of my program Activity A (TabHost) --> Tab 1 (ActivityGroup) --> MainTab1Activity1

So Here's the basic structure of my program

Activity A (TabHost) --> Tab 1 (ActivityGroup) --> MainTab1Activity1

Everything is fine and hunky dory if I use Tab 1 to call MediaStore.ACTION_IMAGE_CAPTURE, however if I want a result, and I try (Tab 1 . startIntentForResult instead of startChildActivity), it tries to go back to Activity A and then crashes since it tries to reallocate resources currently being used.

My question is how do I get Tab 1 to get the result (I already have a pass through method for Tab 1 to MainTabACtivity1 so if I can get the result there, I am golden. Any help would be greatly appreciated :)

Activty A Code:

intent = new Intent().setClass(this, Tab1Group.class);
intent.putExtra(main.USERNAME_RESULT, getIntent().getStringExtra(main.USERNAME_RESULT));
spec = tabHost.newTabSpec("tab1").setIndicator("Tab1Group", 
res.getDrawable(R.drawable.ic_tab_animals)).setContent(intent);
tabHost.addTab(spec);`

Tab1Group *Activity Group"

Intent faIntent = new Intent(this,MainTab1Activity1.class);
startChildActivity("MainTab1开发者_如何学GoActivity1",faIntent);

MainTab1Activity1

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra("output", "EXTRA_OUTPUT");
Calendar c = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("yyyyy_MMM_dd_hh_mm_ss_aaa");
intent.putExtra(MediaStore.EXTRA_OUTPUT,Uri.fromFile(
new File(FindAnimal.fileOutput+"/"+"Random"+sdf.format(c.getTime())+
"_"+currentImageValue+".jpg")));
intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());
Tab1GroupparentActivity = (Tab1Group)getParent();
parentActivity.startChildActivity("TakePic",intent);
//parentActivity.startIntentForResult(intent,CAMERA_PICTURE);

So the goal is to get the picture result back from the camera and currently this doesn't happen. If I try the last commented out part, it trys to reinitialize Activity A code.


SO what I wound up doing is using a Standard Activity which I use startActivity and got rid of the group. Then I @Override OnWindowFocusChange to control whether or not the window is getting back it's focus. I then use a temporary static data holder.

Here is my controller:

public class CameraResultController extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
        // Calendar c = Calendar.getInstance();
       //  SimpleDateFormat sdf = new SimpleDateFormat("yyyyy_MMM_dd_hh_mm_ss_aaa");
        // intent.putExtra(MediaStore.EXTRA_OUTPUT,Uri.fromFile(new File(FindAnimal.fileOutput+"/AnimalFound_"+sdf.format(c.getTime())+"_"+getIntent().getStringExtra(FindAnimal.NumAnimalsSubmit)+".jpg")));
         //intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());
         startActivityForResult(intent, main.CAMERA_PICTURE);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        Log.d("CAMERA RESULT", "Got Result");
        if(requestCode==main.CAMERA_PICTURE) {
            if(resultCode == Activity.RESULT_OK) {
                Uri uriImage = data.getData();
                Bundle extra = data.getExtras();
                CameraPictureData.currentCameraURI = uriImage;
            }else
                CameraPictureData.currentCameraURI = null;
        }
        super.onActivityResult(requestCode, resultCode, data);
        finish();
    }
}

public class CameraPictureData {

    public static Uri currentCameraURI = null; 

}

And then in the OnWindowFocus access the CameraPictureData.

0

精彩评论

暂无评论...
验证码 换一张
取 消