为什么stopService仅在一台设备上工作?

时间:2020-08-01 09:00:03

标签: java android android-intent android-activity service

当用户离开我的应用程序时,将执行stopService()以便停止运行正在播放音乐的服务,但是,如果我在手机上使用我的应用程序,则可以完美运行(如果我在其他手机上使用它,例如我的(完全相同,android,模型)它不再工作了。有什么合理的解释吗?

@OnLifecycleEvent(Lifecycle.Event.ON_STOP)
private void onAppBackgrounded() {
    Log.d("MyApp", "App in background");

    if (!premiumState) {
        SharedPreferences.Editor editor = getSharedPreferences("Preferences", MODE_PRIVATE).edit();
        editor.putString("initialize_player_before_exit", "ok");
        editor.putString("message_for_free_user", "ok");
        editor.apply();

        Intent intent = new Intent(InicioActivity.this, AudioPlayerService.class);
        stopService(intent);
    }
}

@OnLifecycleEvent(Lifecycle.Event.ON_START)
private void onAppForegrounded() {
    Log.d("MyApp", "App in foreground");
}

0 个答案:

没有答案