@TargetApi(14) public static void setAutoSession(Application application) { MWConfiguration.initContext(application.getApplicationContext()); if (VERSION.SDK_INT >= 14) { try { ActivityLifecycleCallbacks xVar = new x(); application.unregisterActivityLifecycleCallbacks(xVar); application.registerActivityLifecycleCallbacks(xVar); m.a().h(true); } catch (NoSuchMethodError e) { m.a().h(false); } catch (NoClassDefFoundError e2) { m.a().h(false); } } }
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) private static void initApp(Context context) { Application application = (Application) mAppContext; if (application != null) { mAppInited = true; if (mLifecycleCallbacks == null) { mLifecycleCallbacks = new PXLifecycleCallbacks(); } application .unregisterActivityLifecycleCallbacks((ActivityLifecycleCallbacks) mLifecycleCallbacks); application .registerActivityLifecycleCallbacks((ActivityLifecycleCallbacks) mLifecycleCallbacks); } }
private ActivityLifecycleCallbacks getLifeCycle(Activity activity){ String fullName=activity.getClass().getName(); //通过activity的名字获取对应的生命周期注册对象 if(manager!=null){ return manager.getLifecycle(fullName); } return null; }
@Override public void onActivityCreated(Activity activity, Bundle savedInstanceState) { ActivityLifecycleCallbacks callbacks=getLifeCycle(activity); if(callbacks!=null){ callbacks.onActivityCreated(activity,savedInstanceState); } }
@Override public void onActivityStarted(Activity activity) { ActivityLifecycleCallbacks callbacks=getLifeCycle(activity); if(callbacks!=null){ callbacks.onActivityStarted(activity); } }
@Override public void onActivityResumed(Activity activity) { ActivityLifecycleCallbacks callbacks=getLifeCycle(activity); if(callbacks!=null){ callbacks.onActivityResumed(activity); } }
@Override public void onActivityPaused(Activity activity) { ActivityLifecycleCallbacks callbacks=getLifeCycle(activity); if(callbacks!=null){ callbacks.onActivityPaused(activity); } }
@Override public void onActivityStopped(Activity activity) { ActivityLifecycleCallbacks callbacks=getLifeCycle(activity); if(callbacks!=null){ callbacks.onActivityStopped(activity); } }
@Override public void onActivitySaveInstanceState(Activity activity, Bundle outState) { ActivityLifecycleCallbacks callbacks=getLifeCycle(activity); if(callbacks!=null){ callbacks.onActivitySaveInstanceState(activity,outState); } }
@Override public void onActivityDestroyed(Activity activity) { ActivityLifecycleCallbacks callbacks=getLifeCycle(activity); if(callbacks!=null){ callbacks.onActivityDestroyed(activity); } }
@Test public void registersCallbacks() { recognizer.start(); verify(mockApplication).registerActivityLifecycleCallbacks(any(ActivityLifecycleCallbacks.class)); verify(mockApplication).registerComponentCallbacks(any(ComponentCallbacks2.class)); verify(mockApplication).registerReceiver(any(BroadcastReceiver.class), any(IntentFilter.class)); }
@Test public void unregistersCallbacks() { recognizer.start(); recognizer.stop(); verify(mockApplication).unregisterActivityLifecycleCallbacks(any(ActivityLifecycleCallbacks.class)); verify(mockApplication).unregisterComponentCallbacks(any(ComponentCallbacks2.class)); verify(mockApplication).unregisterReceiver(any(BroadcastReceiver.class)); }
@TargetApi(ICE_CREAM_SANDWICH) private void setActivityToCreated() { final ArgumentCaptor<ActivityLifecycleCallbacks> captor = forClass(ActivityLifecycleCallbacks.class); verify(application).registerActivityLifecycleCallbacks(captor.capture()); final ActivityLifecycleCallbacks callbacks = captor.getValue(); callbacks.onActivityCreated(activity, null); }
@TargetApi(ICE_CREAM_SANDWICH) private void setActivityToDestroyed() { final ArgumentCaptor<ActivityLifecycleCallbacks> captor = forClass(ActivityLifecycleCallbacks.class); verify(application).registerActivityLifecycleCallbacks(captor.capture()); final ActivityLifecycleCallbacks callbacks = captor.getValue(); callbacks.onActivityDestroyed(activity); }
@TargetApi(ICE_CREAM_SANDWICH) private void setActivityToResumed() { final ArgumentCaptor<ActivityLifecycleCallbacks> captor = forClass(ActivityLifecycleCallbacks.class); verify(application).registerActivityLifecycleCallbacks(captor.capture()); final ActivityLifecycleCallbacks callbacks = captor.getValue(); callbacks.onActivityResumed(activity); }
@TargetApi(ICE_CREAM_SANDWICH) private void setActivityToPaused() { final ArgumentCaptor<ActivityLifecycleCallbacks> captor = forClass(ActivityLifecycleCallbacks.class); verify(application).registerActivityLifecycleCallbacks(captor.capture()); final ActivityLifecycleCallbacks callbacks = captor.getValue(); callbacks.onActivityPaused(activity); }
@TargetApi(ICE_CREAM_SANDWICH) private void setActivityToStarted() { final ArgumentCaptor<ActivityLifecycleCallbacks> captor = forClass(ActivityLifecycleCallbacks.class); verify(application).registerActivityLifecycleCallbacks(captor.capture()); final ActivityLifecycleCallbacks callbacks = captor.getValue(); callbacks.onActivityStarted(activity); }
@TargetApi(ICE_CREAM_SANDWICH) private void setActivityToStopped() { final ArgumentCaptor<ActivityLifecycleCallbacks> captor = forClass(ActivityLifecycleCallbacks.class); verify(application).registerActivityLifecycleCallbacks(captor.capture()); final ActivityLifecycleCallbacks callbacks = captor.getValue(); callbacks.onActivityStopped(activity); }
@TargetApi(ICE_CREAM_SANDWICH) private void saveActivityInstanceState() { final ArgumentCaptor<ActivityLifecycleCallbacks> captor = forClass(ActivityLifecycleCallbacks.class); verify(application).registerActivityLifecycleCallbacks(captor.capture()); final ActivityLifecycleCallbacks callbacks = captor.getValue(); callbacks.onActivitySaveInstanceState(activity, null); }
public static void a(Application application) { ActivityLifecycleCallbacks lVar = new l(); application.unregisterActivityLifecycleCallbacks(lVar); application.registerActivityLifecycleCallbacks(lVar); }
@TargetApi(14) private void clearCallbacks() { for (ActivityLifecycleCallbacks callback : this.registeredCallbacks) { this.application.unregisterActivityLifecycleCallbacks(callback); } }