我陷入困境,根据我的应用程序图表流程描述如下:
假设我在活动A上,在按钮上点击我从图库中选择图像并在选择之后,我将转移到活动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();
}
}
}
}
由于
答案 0 :(得分:0)
它似乎是活动B中的一个例外。正如大家所建议的那样,在B中调试OnActivityResult函数。检查你是否正在检索函数中'System.out.println(path)'打印的正确路径。 / p>