gpt4 book ai didi

Android onActivityResult

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:28:10 28 4
gpt4 key购买 nike

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

假设我在 Activity A 上,在单击按钮时,我从图库中选择图像,选择后,我将移动到 Activity B(它在内部来自 onActivity 结果 - 通过传递 Intent )。现在,当我在 Activity B 上并单击 Button 时,会调用 Custom Video maker。在这里,我拍摄了 10 秒的视频,然后我使用

完成了( Activity C)
C.this.finish();

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

代码:

点击按钮的 Activity B 代码 fragment :

 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();
}
}
}

Activity 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();
}
}


}
}

谢谢

最佳答案

它似乎是 Activity B 中的异常。正如大家所建议的,调试 B 中的 OnActivityResult 函数。检查您是否正在检索函数中“System.out.println(path)”打印的正确路径。

关于Android onActivityResult,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13946669/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com