点击按钮打开一个新的窗口 关键词(Intent, setData , putExtra , startActivity |Bundle)

时间:2021-07-30 06:11:36
M3U8_Video_demo 项目
//------------------ 创建发送
private void playVideo(String source, String title) {
if (source == null || source.equals("")) {
Toast.makeText(this, "视频内容不存在!", Toast.LENGTH_LONG).show();
source = "http://ad.i5suoi.com/video/94.m3u8";
Intent intent = new Intent(this, VideoActivity.class);//VideoActivity 是一个完整的xml 窗口
        intent.setData(Uri.parse(source));
intent.putExtra("mVideoTitle", title);
startActivity(intent);
} else {
Intent intent = new Intent(this, VideoActivity.class);
intent.setData(Uri.parse(source));//m3u8链接 链接都必须Uri.parse 处理吧? intent.putExtra("mVideoTitle", title);//播放标题
        startActivity(intent);//开始新窗体?
}
}
//-----------------接收
初始化的时候调用
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); setContentView(R.layout.play_video); PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
mWakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, POWER_LOCK); Uri uriPath = getIntent().getData();//m3u8链接
   mVideoTitle = getIntent().getStringExtra("mVideoTitle");//播放标题
   if (null != uriPath) {
String scheme = uriPath.getScheme();
if (null != scheme) {
mVideoSource = uriPath.toString();
} else {
mVideoSource = uriPath.getPath();
}
} initUI();
android-tivi github项目
///-----方法2
protected Void doInBackground(Integer... params) {//创建
int id = params[0];
intent = new Intent(getActivity().getApplicationContext(), WatchTvActivity.class);//WatchTvActivity 是一个完整的窗体
    Bundle bundle = new Bundle();
bundle.putInt("id", id);//传递id索引
intent.putExtras(bundle);
return null;
}
protected void onPostExecute(Void aVoid) {//检查
super.onPostExecute(aVoid);//这是个异步处理
if (dialog != null) dialog.dismiss();
startActivity(intent);//打开
}
//--------获取
Bundle bundle = getIntent().getExtras();
id = bundle.getInt("id");