>我有一个活动来显示来自YouTube的视频列表。单击项目时,它会使用以下代码播放视频。但是在按下后,什么也没发生。谁能告诉我如何回到以前的活动?
public class VideoPlayer extends YouTubeBaseActivity implements YouTubePlayer.OnInitializedListener {
private String videoId;
private static final int REQ_START_STANDALONE_PLAYER = 1;
private final static String DBUG = VideoPlayer.class.getSimpleName();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video_player);
Intent in = getIntent();
videoId = in.getStringExtra("videoId");
System.out.println("VideoId received :::"+videoId);
Intent intent = YouTubeStandalonePlayer.createVideoIntent(this, Constants.DEVELOPER_KEY, videoId,0,false,false);
startActivityForResult(intent, 1);
}
@Override
public void onBackPressed() {
// TODO Auto-generated method stub
super.onBackPressed();
Log.v(DBUG, "Back has been pressed::");
finishActivity(REQ_START_STANDALONE_PLAYER);
finish();
}
}
哦,
我找到了答案。我使用意图代替初始化YouTube播放器视图。
private String videoId;
private final static String DBUG = VideoPlayer.class.getSimpleName();
private YouTubePlayerView youtuber;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video_player);
Intent in = getIntent();
videoId = in.getStringExtra("videoId");
System.out.println("VideoId received :::"+videoId);
youtuber = (YouTubePlayerView) findViewById(R.id.youtube_view);
youtuber.initialize(Constants.DEVELOPER_KEY, this);
}
@Override
public void onInitializationSuccess(Provider arg0, YouTubePlayer arg1,
boolean arg2) {
// TODO Auto-generated method stub
Log.v(DBUG, "Playing video");
arg1.cueVideo(videoId);
}
尝试将onBackPressed()更改为onKeyDown(),如下所示:
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
Log.v(DBUG, "Back has been pressed::");
finishActivity(REQ_START_STANDALONE_PLAYER);
finish();
return true;
}