我的项目中有两项活动。主活动中有一个按钮,当我单击它时,它会将我带到第二个活动。当我按下后退按钮时,它不会进入主要活动。它首先检查互联网,然后当我单击按钮时,它会将我带到第二个活动。public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN); try { this.getSupportActionBar().hide(); }catch (Exception e){ } if (isNetworkConnected(this)) { Button button = findViewById(R.id.button); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent activity2Intent = new Intent(getApplicationContext(), playlive.class); startActivity(activity2Intent); } }); } else { buildDialog(MainActivity.this).show(); } } public static boolean isNetworkConnected(Context context) { boolean result = false; ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (cm != null) { NetworkCapabilities capabilities = cm.getNetworkCapabilities(cm.getActiveNetwork()); if (capabilities != null) { if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)) { result = true; } else if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)) { result = true; } } } }
2 回答
哆啦的时光机
TA贡献1779条经验 获得超6个赞
在第二个Activity 的 onDestory 和 onStop 两个方法中添加双重检查。
if (player != null) { player.release; }
添加将其移动到 super.onStop(); 行之前 或 super.onDestroy()
千万里不及你
TA贡献1784条经验 获得超9个赞
你的全局变量private SimpleExoPlayer player;
总是 null
我想你应该在这里初始化它
private void play() { player = ExoPlayerFactory.newSimpleInstance(this);...
而不是创建新实例
添加回答
举报
0/150
提交
取消