Реагировать на адаптивный макет без CSS

Попробуйте выполнить остановку фоновой музыки в HOME или BACK.

@Override
protected void onStop() {
    super.onStop();
    ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningTaskInfo> services = activityManager
            .getRunningTasks(Integer.MAX_VALUE);
    boolean isActivityFound = false;

    if (services.get(0).topActivity.getPackageName().toString()
            .equalsIgnoreCase(getPackageName().toString())) {
        isActivityFound = true; // Activity belongs to your app is in foreground.
    }

    if (!isActivityFound) {
        if (player != null && player.isPlaying()) {
            player.release();
        }
    }
}
30
задан m1gu3l 1 February 2017 в 15:12
поделиться