5

我陷入了一种情况,根据我的应用程序图表流程描述如下:

假设我在 Activity A 上,在单击按钮时,我从图库中挑选图像,挑选后,我将移至 Activity B(它来自 onActivity 结果内部 - 通过传递 Intent )。现在,当我在活动 B 上并单击按钮时,会调用自定义视频制作器。在这里,我拍摄了一个 10 秒的视频,然后我完成了(活动 C)使用

C.this.finish();

现在根据Android活动流程我应该回到活动B,但在我的情况下,我得到一个黑屏几秒钟,然后得到活动A,而不是活动B。我不能透露我的代码,所以我我没有附上它。对不起,同样。如果有人可以帮助我提供这么多信息,请帮助我

代码:

单击按钮的活动 B 代码段:

 btnTakeVideo.setOnClickListener(new OnClickListener() {
            public void onClick(View arg0) {                
                Intent takePictureIntent = new Intent(TakeAnotherPhoto.this,Recorder.class);

                startActivityForResult(takePictureIntent,CreateAuctionScreen.ACTION_TAKE_VIDEO);
            }
        });

这是 onActivityResult

onActivityResult()
if(requestCode == CreateAuctionScreen.ACTION_TAKE_VIDEO) {
            if (resultCode == RESULT_OK) {
                if(CreateAuctionScreen.resetBitmap!=null)
                {                
                    CreateAuctionScreen.resetBitmap = null;
                }                
                Drawable dd;
                dd = getResources().getDrawable(R.drawable.list_pic_frame2x);
                CreateAuctionScreen.bmpSize = ((BitmapDrawable)dd).getBitmap();

                if(data != null){


                    Uri str = data.getData();
                    String path = getRealPathFromURI(str);
                    System.out.println(path);

                    Bitmap bmp = ThumbnailUtils.createVideoThumbnail(path, MediaStore.Images.Thumbnails.MINI_KIND);
                    CreateAuctionScreen.resetBitmap = Bitmap.createScaledBitmap(bmp, CreateAuctionScreen.bmpSize.getWidth(), CreateAuctionScreen.bmpSize.getHeight(), true);

                    if(CreateAuctionScreen.resetBitmap != null){

                        if(CreateAuctionScreen.thumbList.size() < 20){
                            dpv.set_chkString("Video");
                            dpv.get_chkString();
                            CreateAuctionScreen.chkList.add(dpv);
                            CreateAuctionScreen.str_thumbList.add(path);
                            CreateAuctionScreen.thumbList.add(CreateAuctionScreen.resetBitmap);

                            hl.setAdapter(new GallaryImageAdapter(TakeAnotherPhoto.this,CreateAuctionScreen.thumbList.size(),ImageAdapter.CREAT_AUCTION_SCREEN, CreateAuctionScreen.thumbList));
                        }else{
                            Toast.makeText(TakeAnotherPhoto.this, "You can add up to 20 pics & videos only", Toast.LENGTH_SHORT).show();
                        }
                    }
                }

活动 C(客户录像机)

public class Recorder extends Activity implements SurfaceHolder.Callback{

    Button myButton;
    MediaRecorder mediaRecorder;
    SurfaceHolder surfaceHolder;
    boolean back;
    Timer timer;
    int counter = 1;
    String strPath;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        back = false;

        mediaRecorder = new MediaRecorder();
        setContentView(R.layout.recorde);
        initMediaRecorder();

        timer = new Timer();
        TimerTask timerTask = new TimerTask() {
            @Override
            public void run() {
                if(counter<=10)
                    counter++;
                //Android UI get Updated continouly
                else {
                    // If condition full filled the timer will stop here
                    mediaRecorder.stop();
                    mediaRecorder.release();
                    timer.cancel();
                    Intent i = new Intent();
                    setResult(RESULT_OK, i.putExtra("returnedVideo", strPath));

                    Recorder.this.finish();

                }
            } 
        };
        timer.schedule(timerTask, 1000, 1000);

        SurfaceView myVideoView = (SurfaceView)findViewById(R.id.videoview);
        surfaceHolder = myVideoView.getHolder();
        surfaceHolder.addCallback(this);
        surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

        myButton = (Button)findViewById(R.id.mybutton);
        myButton.setOnClickListener(myButtonOnClickListener);
    }

    private Button.OnClickListener myButtonOnClickListener
    = new Button.OnClickListener(){

        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            mediaRecorder.stop();
            mediaRecorder.release();
            timer.cancel();

            Intent i = new Intent();
            setResult(RESULT_OK, i.putExtra("returnedVideo", strPath));
//            i.putExtra("returnedVideo", strPath);
//            i.putExtra("isRecorder", true);
//            startActivity(i);
            finish();
        }};

        public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {
            // TODO Auto-generated method stub

        }
        public void surfaceCreated(SurfaceHolder arg0) {
            // TODO Auto-generated method stub
            prepareMediaRecorder();
        }
        public void surfaceDestroyed(SurfaceHolder arg0) {
            // TODO Auto-generated method stub

            mediaRecorder.stop();
            mediaRecorder.release();
            //Recorder.this.finish();
        }

        @Override
        public void onBackPressed() {
            // TODO Auto-generated method stub
            super.onBackPressed();

            mediaRecorder.stop();
            mediaRecorder.release();
        }

        private void initMediaRecorder(){
            Random genraotr = new Random();
            int n = 10000;
            n = genraotr.nextInt(n);            

            mediaRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
            mediaRecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
            CamcorderProfile camcorderProfile_HQ = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH);
            mediaRecorder.setProfile(camcorderProfile_HQ);
            mediaRecorder.setOutputFile("/sdcard/auction_video"+n+".mp4");
            strPath = "/sdcard/auction_video"+n+".mp4";
            mediaRecorder.setMaxDuration(10000); // Set max duration 10 sec.
            mediaRecorder.setMaxFileSize(5000000); // Set max file size 5M
        }

        private void prepareMediaRecorder(){
            mediaRecorder.setPreviewDisplay(surfaceHolder.getSurface());
            try {
                mediaRecorder.prepare();
                mediaRecorder.start();
            } catch (IllegalStateException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }


        }
}

谢谢

4

1 回答 1

0

It appears to be a exception in Activity B. As everyone has suggested, debug OnActivityResult function in B. Check if you are retrieving the right path as printed by 'System.out.println(path)' in your function.

于 2012-12-31T10:33:10.600 回答