我有一个父活动A,它有两个子活动B和C.当我打开父活动A时,它决定必须打开哪个子活动。 (使用startActivityForResult
的功能)例如。决定打开B. B播放视频并返回结果。如果A决定再次打开B,那就好了。 B打不开(不播放视频)。
注意: 以下是好的:
A - > B和A< -B
然后
A - > C和A < - C
然后
A - > B和A&lt; -B
但是以下不起作用:
A - > B和A&lt; -B
然后
A - &gt; B和A&lt; - B //当尝试再次移动B.我认为A在完成之前再次呼叫B
然后
A - > C和A < - C
任何解决这个问题的想法??
意味着我怎样才能在再次召唤孩子之前完成孩子的活动?
以下是父活动的代码:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.d(Constants.TAG,"requestCode: "+requestCode+" : resultCode : "+ resultCode);
finishActivity(requestCode);
playProgram(requestCode);
}
private void playProgram(int requestCode){
if(requestCode == QUESTION_WRAPPER){
currentChap = currentChap + 1;
Intent intent = new Intent(MovieWrapperActivity.this, VideoWrapperActivity.class);
intent.putExtra("chaptertoplay", currentChap);
intent.putExtra("videofile", Constants.mCourse.getmChapters().get(currentChap).getVideoURL());
startActivityForResult(intent, MOVIE_WRAPPER);
}else if(requestCode == MOVIE_WRAPPER) {
if(Constants.mCourse.getmChapters().get(currentChap).isQuiz()){
Intent in2 = new Intent(MovieWrapperActivity.this, QuestionWrapper.class);
in2.putExtra("chaptertoplay", currentChap);
startActivityForResult(in2, QUESTION_WRAPPER);
}else{
currentChap = currentChap + 1;
Intent intent = new Intent(MovieWrapperActivity.this, VideoWrapperActivity.class);
intent.putExtra("chaptertoplay", currentChap);
intent.putExtra("videofile", Constants.mCourse.getmChapters().get(currentChap).getVideoURL());
startActivityForResult(intent, MOVIE_WRAPPER);
}
}
}
B代码:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (!io.vov.vitamio.LibsChecker.checkVitamioLibs(this))
return;
setContentView(R.layout.videoview);
init();
mVideoView = (VideoView) findViewById(R.id.surface_view);
mVideoView.setVideoPath(videoPath);
mVideoView.setVideoQuality(MediaPlayer.VIDEOQUALITY_HIGH);
mController = new MediaController(this);
mVideoView.setMediaController(mController);
mVideoView.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer arg0) {
Log.d(Constants.TAG,"Completed");
Intent returnIntent = new Intent();
setResult(RESULT_OK, returnIntent);
mVideoView = null;
mController = null;
finish();
}
});
}
我认为B中的媒体元素需要时间来摧毁甚至不被摧毁。
答案 0 :(得分:0)
Intent output = new Intent();
output.putExtra("DATA", data);
setResult(Activity.RESULT_OK , output);
finish();
设置结果后,只需致电finish()
即可。
答案 1 :(得分:0)
你必须在子活动中的setresult()之后调用finish()。
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.d(Constants.TAG,"requestCode: "+requestCode+" : resultCode : "+ resultCode);
finishActivity(requestCode);//dont finish child activity here.
playProgram(requestCode);
}