我的項(xiàng)目中有兩項(xiàng)活動(dòng)。主活動(dòng)中有一個(gè)按鈕,當(dāng)我單擊它時(shí),它會(huì)將我?guī)У降诙€(gè)活動(dòng)。當(dāng)我按下后退按鈕時(shí),它不會(huì)進(jìn)入主要活動(dòng)。它首先檢查互聯(lián)網(wǎng),然后當(dāng)我單擊按鈕時(shí),它會(huì)將我?guī)У降诙€(gè)活動(dòng)。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 回答

哆啦的時(shí)光機(jī)
TA貢獻(xiàn)1779條經(jīng)驗(yàn) 獲得超6個(gè)贊
在第二個(gè)Activity 的 onDestory 和 onStop 兩個(gè)方法中添加雙重檢查。
if (player != null) { player.release; }
添加將其移動(dòng)到 super.onStop(); 行之前 或 super.onDestroy()

千萬里不及你
TA貢獻(xiàn)1784條經(jīng)驗(yàn) 獲得超9個(gè)贊
你的全局變量private SimpleExoPlayer player;
總是 null
我想你應(yīng)該在這里初始化它
private void play() { player = ExoPlayerFactory.newSimpleInstance(this);...
而不是創(chuàng)建新實(shí)例
添加回答
舉報(bào)
0/150
提交
取消