阅读量:0
- 设置Activity的最大生命周期为onStop:
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getLifecycle().setMaxLifecycle(this, Lifecycle.State.CREATED); }
- 设置Fragment的最大生命周期为onPause:
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); getLifecycle().setMaxLifecycle(this, Lifecycle.State.STARTED); }
- 设置Service的最大生命周期为onDestroy:
@Override public int onStartCommand(Intent intent, int flags, int startId) { super.onStartCommand(intent, flags, startId); getLifecycle().setMaxLifecycle(this, Lifecycle.State.STARTED); }