android.arch.lifecycle.OnLifecycleEvent Java Examples
The following examples show how to use
android.arch.lifecycle.OnLifecycleEvent.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NavigationScene.java From scene with Apache License 2.0 | 6 votes |
@MainThread public void addOnBackPressedListener(@NonNull final LifecycleOwner lifecycleOwner, @NonNull final OnBackPressedListener onBackPressedListener) { ThreadUtility.checkUIThread(); if (lifecycleOwner.getLifecycle().getCurrentState() == DESTROYED) { // ignore return; } this.mNavigationSceneManager.addOnBackPressedListener(lifecycleOwner, onBackPressedListener); lifecycleOwner.getLifecycle().addObserver(new LifecycleObserver() { @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY) void onDestroy() { lifecycleOwner.getLifecycle().removeObserver(this); mNavigationSceneManager.removeOnBackPressedListener(onBackPressedListener); } }); }
Example #2
Source File: SceneActivityCompatibilityLayerFragment.java From scene with Apache License 2.0 | 6 votes |
@MainThread void startActivityForResultByScene(@NonNull final LifecycleOwner lifecycleOwner, @NonNull Intent intent, final int requestCode, @NonNull ActivityResultCallback resultCallback) { if (!isCurrentStatusValid(lifecycleOwner)) { return; } if (requestCode < 0) { startActivity(intent); return; } mResultCallbackMap.put(requestCode, resultCallback); startActivityForResult(intent, requestCode); lifecycleOwner.getLifecycle().addObserver(new LifecycleObserver() { @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY) void onDestroy() { lifecycleOwner.getLifecycle().removeObserver(this); mResultCallbackMap.remove(requestCode); } }); }
Example #3
Source File: SceneActivityCompatibilityLayerFragment.java From scene with Apache License 2.0 | 6 votes |
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN) @MainThread void startActivityForResultByScene(@NonNull final LifecycleOwner lifecycleOwner, @NonNull Intent intent, final int requestCode, @Nullable Bundle options, @NonNull ActivityResultCallback resultCallback) { if (!isCurrentStatusValid(lifecycleOwner)) { return; } if (requestCode < 0) { startActivity(intent); return; } mResultCallbackMap.put(requestCode, resultCallback); startActivityForResult(intent, requestCode, options); lifecycleOwner.getLifecycle().addObserver(new LifecycleObserver() { @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY) void onDestroy() { lifecycleOwner.getLifecycle().removeObserver(this); mResultCallbackMap.remove(requestCode); } }); }
Example #4
Source File: SceneActivityCompatibilityLayerFragment.java From scene with Apache License 2.0 | 6 votes |
@MainThread @RequiresApi(Build.VERSION_CODES.M) void requestPermissionsByScene(@NonNull final LifecycleOwner lifecycleOwner, @NonNull String[] permissions, final int requestCode, @NonNull final PermissionResultCallback resultCallback) { if (!isCurrentStatusValid(lifecycleOwner)) { return; } mPermissionResultCallbackMap.put(requestCode, resultCallback); requestPermissions(permissions, requestCode); lifecycleOwner.getLifecycle().addObserver(new LifecycleObserver() { @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY) void onDestroy() { lifecycleOwner.getLifecycle().removeObserver(this); mPermissionResultCallbackMap.remove(requestCode); } }); }
Example #5
Source File: RtmpPublisher.java From RtmpPublisher with Apache License 2.0 | 6 votes |
@OnLifecycleEvent(Lifecycle.Event.ON_PAUSE) public void onPause(LifecycleOwner owner) { if (camera != null) { camera.close(); } glView.onPause(); glView.queueEvent(new Runnable() { @Override public void run() { renderer.pause(); } }); if (streamer.isStreaming()) { streamer.stopStreaming(); } }
Example #6
Source File: HomeActivity.java From alpha-wallet-android with MIT License | 5 votes |
public HomeActivity() { importFileName = null; if (VisibilityFilter.hideDappBrowser()) dappBrowserFragment = new Fragment(); else dappBrowserFragment = new DappBrowserFragment(); transactionsFragment = new TransactionsFragment(); settingsFragment = new NewSettingsFragment(); walletFragment = new WalletFragment(); lifeCycle = new LifecycleObserver() { @OnLifecycleEvent(Lifecycle.Event.ON_START) private void onMoveToForeground() { Log.d("LIFE", "AlphaWallet into foreground"); ((WalletFragment)walletFragment).walletInFocus(); } @OnLifecycleEvent(Lifecycle.Event.ON_STOP) private void onMoveToBackground() { Log.d("LIFE", "AlphaWallet into background"); ((WalletFragment)walletFragment).walletOutOfFocus(); } @Override public int hashCode() { return super.hashCode(); } }; ProcessLifecycleOwner.get().getLifecycle().addObserver(lifeCycle); }
Example #7
Source File: SceneActivityCompatibilityLayerFragment.java From scene with Apache License 2.0 | 5 votes |
@MainThread void addConfigurationChangedListener(@NonNull final LifecycleOwner lifecycleOwner, @NonNull final ConfigurationChangedListener configurationChangedListener) { if (!isCurrentStatusValid(lifecycleOwner)) { return; } mConfigurationChangedListenerList.add(configurationChangedListener); lifecycleOwner.getLifecycle().addObserver(new LifecycleObserver() { @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY) void onDestroy() { lifecycleOwner.getLifecycle().removeObserver(this); mConfigurationChangedListenerList.remove(configurationChangedListener); } }); }
Example #8
Source File: TypedTextView.java From TypedTextView with Apache License 2.0 | 5 votes |
@OnLifecycleEvent( Lifecycle.Event.ON_START ) void onViewStarted() { //resume typing if view was stopped before entire text was displayed. if( mText != null && mIndex != 0 && mIndex != mText.length() ) { //resume playing keystrokes playKeystrokes(); mHandler.postDelayed( mTypeWriter, mTypingSpeedMillis ); } }
Example #9
Source File: TypedTextView.java From TypedTextView with Apache License 2.0 | 5 votes |
@OnLifecycleEvent( Lifecycle.Event.ON_STOP ) void onViewStopped() { //stop typing as view is now in stopped state. removeCallbacks(); //pause playing keystrokes pauseKeyStrokes(); }
Example #10
Source File: AppLifeCycleObserver.java From android-mvp-realtime-chat with MIT License | 5 votes |
/** * When app enters foreground */ @OnLifecycleEvent(Lifecycle.Event.ON_START) public void onEnterForeground() { try { EventServiceImpl.getInstance().connect(User.getUsername()); } catch (URISyntaxException e) { Toast.makeText(mContext, "Failed to connect to chat server.", Toast.LENGTH_LONG).show(); e.printStackTrace(); } }
Example #11
Source File: RtmpPublisher.java From RtmpPublisher with Apache License 2.0 | 5 votes |
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME) public void onResume(LifecycleOwner owner) { Camera.Parameters params = camera.open(); final Camera.Size size = params.getPreviewSize(); glView.onResume(); glView.queueEvent(new Runnable() { @Override public void run() { renderer.setCameraPreviewSize(size.width, size.height); } }); }
Example #12
Source File: BasePresenter.java From Aurora with Apache License 2.0 | 5 votes |
/** * 只有当 {@code mRootView} 不为 null, 并且 {@code mRootView} 实现了 {@link LifecycleOwner} 时, 此方法才会被调用 * 所以当您想在 {@link Service} 以及一些自定义 {@link View} 或自定义类中使用 {@code Presenter} 时 * 您也将不能继续使用 {@link OnLifecycleEvent} 绑定生命周期 * * @param owner link {@link SupportActivity} and {@link Fragment} */ @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY) void onDestroy(LifecycleOwner owner) { /** * 注意, 如果在这里调用了 {@link #onDestroy()} 方法, 会出现某些地方引用 {@code mModel} 或 {@code mRootView} 为 null 的情况 * 比如在 {@link RxLifecycle} 终止 {@link Observable} 时, 在 {@link io.reactivex.Observable#doFinally(Action)} 中却引用了 {@code mRootView} 做一些释放资源的操作, 此时会空指针 * 或者如果你声明了多个 @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY) 时在其他 @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY) * 中引用了 {@code mModel} 或 {@code mRootView} 也可能会出现此情况 */ owner.getLifecycle().removeObserver(this); }
Example #13
Source File: MainActivityPresenter.java From MVP-Architecture-Components with Apache License 2.0 | 5 votes |
@OnLifecycleEvent(value = Lifecycle.Event.ON_CREATE) protected void onCreate() { if (viewStateBundle.getBoolean(PROGRESS_BAR_STATE_KEY)) { if (isViewAttached()) getView().showProgress(); } }
Example #14
Source File: Flutter.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
/** * Creates a {@link FlutterView} linked to the specified {@link Activity} and {@link Lifecycle}. * The optional initial route string will be made available to the Dart code (via * {@code window.defaultRouteName}) and may be used to determine which widget should be displayed * in the view. The default initialRoute is "/". * * @param activity an {@link Activity} * @param lifecycle a {@link Lifecycle} * @param initialRoute an initial route {@link String}, or null * @return a {@link FlutterView} */ @NonNull public static FlutterView createView(@NonNull final Activity activity, @NonNull final Lifecycle lifecycle, final String initialRoute) { FlutterMain.startInitialization(activity.getApplicationContext()); FlutterMain.ensureInitializationComplete(activity.getApplicationContext(), null); final FlutterNativeView nativeView = new FlutterNativeView(activity); final FlutterView flutterView = new FlutterView(activity, null, nativeView) { private final BasicMessageChannel<String> lifecycleMessages = new BasicMessageChannel<>(this, "flutter/lifecycle", StringCodec.INSTANCE); @Override public void onFirstFrame() { super.onFirstFrame(); setAlpha(1.0f); } @Override public void onPostResume() { // Overriding default behavior to avoid dictating system UI via PlatformPlugin. lifecycleMessages.send("AppLifecycleState.resumed"); } }; if (initialRoute != null) { flutterView.setInitialRoute(initialRoute); } lifecycle.addObserver(new LifecycleObserver() { @OnLifecycleEvent(Lifecycle.Event.ON_CREATE) public void onCreate() { final FlutterRunArguments arguments = new FlutterRunArguments(); arguments.bundlePath = FlutterMain.findAppBundlePath(activity.getApplicationContext()); arguments.entrypoint = "main"; flutterView.runFromBundle(arguments); GeneratedPluginRegistrant.registerWith(flutterView.getPluginRegistry()); } @OnLifecycleEvent(Lifecycle.Event.ON_START) public void onStart() { flutterView.onStart(); } @OnLifecycleEvent(Lifecycle.Event.ON_RESUME) public void onResume() { flutterView.onPostResume(); } @OnLifecycleEvent(Lifecycle.Event.ON_PAUSE) public void onPause() { flutterView.onPause(); } @OnLifecycleEvent(Lifecycle.Event.ON_STOP) public void onStop() { flutterView.onStop(); } @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY) public void onDestroy() { flutterView.destroy(); } }); flutterView.setAlpha(0.0f); return flutterView; }
Example #15
Source File: NavigationCamera.java From graphhopper-navigation-android with MIT License | 5 votes |
/** * Call in {@link FragmentActivity#onStart()} to properly add the {@link ProgressChangeListener} * for the camera and prevent any leaks or further updates. * * @since 0.15.0 */ @OnLifecycleEvent(Lifecycle.Event.ON_START) public void onStart() { if (navigation != null) { navigation.addProgressChangeListener(progressChangeListener); } }
Example #16
Source File: NavigationCamera.java From graphhopper-navigation-android with MIT License | 5 votes |
/** * Call in {@link FragmentActivity#onStop()} to properly remove the {@link ProgressChangeListener} * for the camera and prevent any leaks or further updates. * * @since 0.15.0 */ @OnLifecycleEvent(Lifecycle.Event.ON_STOP) public void onStop() { if (navigation != null) { navigation.removeProgressChangeListener(progressChangeListener); } }
Example #17
Source File: GasSliderView.java From alpha-wallet-android with MIT License | 5 votes |
@OnLifecycleEvent(Lifecycle.Event.ON_START) public void start() { disposable = Observable.interval(0, API_CALL_PERIOD, TimeUnit.SECONDS, Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) .map(tick -> getGasTransactionTime(tick) .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) .subscribe(response -> updateDetails(response, tick), this::showError).isDisposed()) .doOnError(this::showError) .subscribe(); }
Example #18
Source File: BaseViewModel.java From MVVMArms with Apache License 2.0 | 5 votes |
@OnLifecycleEvent(Lifecycle.Event.ON_CREATE) @Override public void onStart() { if (useEventBus()) { //注册eventbus EventBus.getDefault().register(this); } }
Example #19
Source File: ConfigResistantObserver.java From robocar with Apache License 2.0 | 5 votes |
@OnLifecycleEvent(Event.ON_STOP) public final void onStop() { mStartCount--; if (mStartCount == 0) { mHandler.postDelayed(mDelayedStopRunnable, TIMEOUT_MS); } }
Example #20
Source File: RxLifecycleObserver.java From RxLifecycle with Apache License 2.0 | 4 votes |
@OnLifecycleEvent(ON_RESUME) public void onViewResumed() { subject.onNext(ON_RESUME); }
Example #21
Source File: VideoPlayerComponent.java From android-arch-components-lifecycle with Apache License 2.0 | 4 votes |
@OnLifecycleEvent(Lifecycle.Event.ON_CREATE) void onCreate() { clearResumePosition(); simpleExoPlayerView.requestFocus(); }
Example #22
Source File: SyncCommentLifecycleObserver.java From OfflineSampleApp with Apache License 2.0 | 4 votes |
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME) public void onResume() { Timber.d("onResume lifecycle event."); disposables.add(SyncCommentRxBus.getInstance().toObservable() .subscribe(this::handleSyncResponse, t -> Timber.e(t, "error handling sync response"))); }
Example #23
Source File: SearchPresent.java From Hands-Chopping with Apache License 2.0 | 4 votes |
@OnLifecycleEvent(Lifecycle.Event.ON_CREATE) void onCreate(){ }
Example #24
Source File: RxLifecycleObserver.java From RxLifecycle with Apache License 2.0 | 4 votes |
@OnLifecycleEvent(ON_STOP) public void onViewStopped() { subject.onNext(ON_STOP); }
Example #25
Source File: RxLifecycleObserver.java From RxLifecycle with Apache License 2.0 | 4 votes |
@OnLifecycleEvent(ON_PAUSE) public void onViewPaused() { subject.onNext(ON_PAUSE); }
Example #26
Source File: ILifeCycleCallBack.java From YImagePicker with Apache License 2.0 | 4 votes |
@OnLifecycleEvent(Lifecycle.Event.ON_PAUSE) void onPause();
Example #27
Source File: VideoPlayerComponent.java From android-arch-components-lifecycle with Apache License 2.0 | 4 votes |
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME) void onResume() { if ((Util.SDK_INT <= 23)) { initializePlayer(); } }
Example #28
Source File: DebugDrawerAddDummyRide.java From android-ponewheel with MIT License | 4 votes |
@Override @OnLifecycleEvent(Lifecycle.Event.ON_PAUSE) public void onPause() { Timber.d("onPause: "); }
Example #29
Source File: DebugDrawerAddDummyRide.java From android-ponewheel with MIT License | 4 votes |
@OnLifecycleEvent(Lifecycle.Event.ON_STOP) @Override public void onStop() { Timber.d("onStop: "); }
Example #30
Source File: ILifeCycleCallBack.java From YImagePicker with Apache License 2.0 | 4 votes |
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME) void onResume();