daily pastebin goal
61%
SHARE
TWEET

Untitled

a guest Mar 22nd, 2018 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class ShopListProductLoaderImpl implements ShopListProductLoader .... {
  2.  
  3.     private FragmentLikeActivity mActivity;
  4.     private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
  5.         @Override
  6.         public void onReceive(Context context, Intent intent) {
  7.             //тут прилетает интент
  8.         }
  9.     };;
  10.  
  11.     public ShopListProductLoaderImpl(FragmentLikeActivity mActivity, Fragment fragment) {
  12.         this.mActivity = mActivity;
  13.         fragment.getLifecycle().addObserver(new ViewLifecycleObserver());
  14.     }
  15.  
  16.     /**
  17.      * подписка/отписка на BroadcastReceiver
  18.      */
  19.     private class ViewLifecycleObserver implements LifecycleObserver {
  20.         @OnLifecycleEvent(ON_CREATE)
  21.         void onCreate() {
  22.             mActivity.registerReceiver(mBroadcastReceiver, SimpleBroadcastReceiver.prepareIntentFilter());
  23.         }
  24.  
  25.         @OnLifecycleEvent(ON_DESTROY)
  26.         void onDestroy() {
  27.             mActivity.unregisterReceiver(mBroadcastReceiver);
  28.         }
  29.     }
  30. }
RAW Paste Data
Top