[英]Android onActivityResult
I am stuck in a situation, which is described as follows in terms of my app chart flow : 我陷入困境,根据我的应用程序图表流程描述如下:
Suppose I am on Activity A, Here at the onclick of a button I pick the images from the gallery and after picking, I am moving to the Activity B ( it comes internally from onActivity result - by passing the Intent ). 假设我在活动A上,在按钮上点击我从图库中选择图像并在选择之后,我将转移到活动B(它来自onActivity结果 - 通过传递Intent)。 Now here when I am on Activity B and click on a Button, there is a call to the Custom Video maker. 现在,当我在活动B上并单击按钮时,会调用自定义视频制作者。 Here I capture a video for 10 secs and then I finished ( Activity C) using 在这里,我捕捉视频10秒,然后我完成(活动C)使用
C.this.finish();
Now as per the Android Activity Flow I SHOULD MOVE BACK TO THE ACTIVITY B, But in my case I am getting one black Screen for few seconds and then getting Activity A, instead of Activity B. I can't disclose my code, so I am not attaching it. 现在根据Android活动流程,我应该回到活动B,但在我的情况下,我得到一个黑屏几秒钟,然后获得活动A,而不是活动B.我不能透露我的代码,所以我我没附上它。 Sorry for the same. 对不起,同样的。 If anybody can help me with this much of info, Please help me 如果有人可以帮我提供这么多信息,请帮助我
code: 码:
Activity B code snippet where the button is clicked : 单击按钮的活动B代码段:
btnTakeVideo.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
Intent takePictureIntent = new Intent(TakeAnotherPhoto.this,Recorder.class);
startActivityForResult(takePictureIntent,CreateAuctionScreen.ACTION_TAKE_VIDEO);
}
});
here is the onActivityResult 这是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 (Custome Video Recorder ) 活动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();
}
}
}
}
Thanks 谢谢
它似乎是活动B中的一个例外。正如大家所建议的那样,在B中调试OnActivityResult函数。检查你是否正在检索函数中'System.out.println(path)'打印的正确路径。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.