我有一个代码,通过mx播放器显示视频,当我第一次启动应用程序时,任何错误,但如果我关闭并再次打开应用程序,它说活动mx播放器没有响应。我怎么能关闭mx播放器当我按下后退按钮。 我的代码:
公共类MainActivity扩展了Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_main);
startMxPlayer(1, 1);
finish();
}
private void startMxPlayer(int tuner, int ch) {
int port = 8000 + tuner * 10 + ch;
Uri uri = Uri.parse("udp://224.1." + (port & 0xff) + ".1:" + port);
Log.v("server", "udp://224.1." + (port & 0xff) + ".1:" + port);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
intent.setPackage( "com.mxtech.videoplayer.ad" );
intent.putExtra("end_by","user");
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_HISTORY);
getApplication().startActivity(intent);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
答案 0 :(得分:1)
没有人可以停止杀死这个过程,但我建议你以其他方式做。
private void startMxPlayer(int tuner, int ch) {
int port = 8000 + tuner * 10 + ch;
Uri uri = Uri.parse("udp://224.1." + (port & 0xff) + ".1:" + port);
Log.v("server", "udp://224.1." + (port & 0xff) + ".1:" + port);
// add the following line.
ActivityManager.killBackgroundProcesses("com.mxtech.videoplayer.ad");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
intent.setPackage( "com.mxtech.videoplayer.ad" );
intent.putExtra("end_by","user");
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_HISTORY);
getApplication().startActivity(intent);