@Test public void testOnActivityPaused() throws Exception { manager.onActivityResumed(activity); assertEquals(false, manager.isBackgrounded()); manager.onActivityPaused(activity); Thread.sleep(1000); assertEquals(true, manager.isBackgrounded()); assertTrue(manager.mInitialized); assertTrue(manager.mLastStoppedTime.get() > 0); manager.onActivityResumed(activity); assertTrue(manager.getSession().getBackgroundTime() + " ms", manager.getSession().getBackgroundTime() >= 1000 && manager.getSession().getBackgroundTime() < 1200); }
public void onActivityPaused(Activity activity) { try { mPreferences.edit().putBoolean(Constants.PrefKeys.CRASHED_IN_FOREGROUND, false).apply(); mLastStoppedTime = new AtomicLong(getTime()); if (mCurrentActivityReference != null && activity == mCurrentActivityReference.get()) { mCurrentActivityReference.clear(); mCurrentActivityReference = null; } delayedBackgroundCheckHandler.postDelayed(new Runnable() { @Override public void run() { try { if (isBackgrounded()) { checkSessionTimeout(); logBackgrounded(); mConfigManager.setPreviousAdId(); } }catch (Exception e){ e.printStackTrace(); } } }, ACTIVITY_DELAY); if (MParticle.getInstance().isAutoTrackingEnabled()) { MParticle.getInstance().logScreen( new MPEvent.Builder(AppStateManager.getActivityName(activity)) .internalNavigationDirection(false) .build() ); } MParticle.getInstance().Internal().getKitManager().onActivityPaused(activity); }catch (Exception e) { Logger.verbose("Failed while trying to track activity pause: " + e.getMessage()); } }
AppStateManager { public void onActivityPaused(Activity activity) { try { mPreferences.edit().putBoolean(Constants.PrefKeys.CRASHED_IN_FOREGROUND, false).apply(); mLastStoppedTime = new AtomicLong(getTime()); if (mCurrentActivityReference != null && activity == mCurrentActivityReference.get()) { mCurrentActivityReference.clear(); mCurrentActivityReference = null; } delayedBackgroundCheckHandler.postDelayed(new Runnable() { @Override public void run() { try { if (isBackgrounded()) { checkSessionTimeout(); logBackgrounded(); mConfigManager.setPreviousAdId(); } }catch (Exception e){ e.printStackTrace(); } } }, ACTIVITY_DELAY); if (MParticle.getInstance().isAutoTrackingEnabled()) { MParticle.getInstance().logScreen( new MPEvent.Builder(AppStateManager.getActivityName(activity)) .internalNavigationDirection(false) .build() ); } MParticle.getInstance().Internal().getKitManager().onActivityPaused(activity); }catch (Exception e) { Logger.verbose("Failed while trying to track activity pause: " + e.getMessage()); } } }
AppStateManager { public void onActivityPaused(Activity activity) { try { mPreferences.edit().putBoolean(Constants.PrefKeys.CRASHED_IN_FOREGROUND, false).apply(); mLastStoppedTime = new AtomicLong(getTime()); if (mCurrentActivityReference != null && activity == mCurrentActivityReference.get()) { mCurrentActivityReference.clear(); mCurrentActivityReference = null; } delayedBackgroundCheckHandler.postDelayed(new Runnable() { @Override public void run() { try { if (isBackgrounded()) { checkSessionTimeout(); logBackgrounded(); mConfigManager.setPreviousAdId(); } }catch (Exception e){ e.printStackTrace(); } } }, ACTIVITY_DELAY); if (MParticle.getInstance().isAutoTrackingEnabled()) { MParticle.getInstance().logScreen( new MPEvent.Builder(AppStateManager.getActivityName(activity)) .internalNavigationDirection(false) .build() ); } MParticle.getInstance().Internal().getKitManager().onActivityPaused(activity); }catch (Exception e) { Logger.verbose("Failed while trying to track activity pause: " + e.getMessage()); } } AppStateManager(Context context, boolean unitTesting);  AppStateManager(Context context); }
AppStateManager { public void onActivityPaused(Activity activity) { try { mPreferences.edit().putBoolean(Constants.PrefKeys.CRASHED_IN_FOREGROUND, false).apply(); mLastStoppedTime = new AtomicLong(getTime()); if (mCurrentActivityReference != null && activity == mCurrentActivityReference.get()) { mCurrentActivityReference.clear(); mCurrentActivityReference = null; } delayedBackgroundCheckHandler.postDelayed(new Runnable() { @Override public void run() { try { if (isBackgrounded()) { checkSessionTimeout(); logBackgrounded(); mConfigManager.setPreviousAdId(); } }catch (Exception e){ e.printStackTrace(); } } }, ACTIVITY_DELAY); if (MParticle.getInstance().isAutoTrackingEnabled()) { MParticle.getInstance().logScreen( new MPEvent.Builder(AppStateManager.getActivityName(activity)) .internalNavigationDirection(false) .build() ); } MParticle.getInstance().Internal().getKitManager().onActivityPaused(activity); }catch (Exception e) { Logger.verbose("Failed while trying to track activity pause: " + e.getMessage()); } } AppStateManager(Context context, boolean unitTesting);  AppStateManager(Context context); void init(int apiVersion); String getLaunchAction(); Uri getLaunchUri(); void setConfigManager(ConfigManager manager); void setMessageManager(MessageManager manager); void onActivityResumed(Activity activity); void onActivityPaused(Activity activity); void ensureActiveSession(); void logStateTransition(String transitionType, String currentActivity); void onActivityCreated(Activity activity, Bundle savedInstanceState); void onActivityStarted(Activity activity); void onActivityStopped(Activity activity); boolean isBackgrounded(); String getCurrentActivityName(); InternalSession getSession(); void endSession(); void startSession(); void onActivitySaveInstanceState(Activity activity, Bundle outState); void onActivityDestroyed(Activity activity); WeakReference<Activity> getCurrentActivity(); }
AppStateManager { public void onActivityPaused(Activity activity) { try { mPreferences.edit().putBoolean(Constants.PrefKeys.CRASHED_IN_FOREGROUND, false).apply(); mLastStoppedTime = new AtomicLong(getTime()); if (mCurrentActivityReference != null && activity == mCurrentActivityReference.get()) { mCurrentActivityReference.clear(); mCurrentActivityReference = null; } delayedBackgroundCheckHandler.postDelayed(new Runnable() { @Override public void run() { try { if (isBackgrounded()) { checkSessionTimeout(); logBackgrounded(); mConfigManager.setPreviousAdId(); } }catch (Exception e){ e.printStackTrace(); } } }, ACTIVITY_DELAY); if (MParticle.getInstance().isAutoTrackingEnabled()) { MParticle.getInstance().logScreen( new MPEvent.Builder(AppStateManager.getActivityName(activity)) .internalNavigationDirection(false) .build() ); } MParticle.getInstance().Internal().getKitManager().onActivityPaused(activity); }catch (Exception e) { Logger.verbose("Failed while trying to track activity pause: " + e.getMessage()); } } AppStateManager(Context context, boolean unitTesting);  AppStateManager(Context context); void init(int apiVersion); String getLaunchAction(); Uri getLaunchUri(); void setConfigManager(ConfigManager manager); void setMessageManager(MessageManager manager); void onActivityResumed(Activity activity); void onActivityPaused(Activity activity); void ensureActiveSession(); void logStateTransition(String transitionType, String currentActivity); void onActivityCreated(Activity activity, Bundle savedInstanceState); void onActivityStarted(Activity activity); void onActivityStopped(Activity activity); boolean isBackgrounded(); String getCurrentActivityName(); InternalSession getSession(); void endSession(); void startSession(); void onActivitySaveInstanceState(Activity activity, Bundle outState); void onActivityDestroyed(Activity activity); WeakReference<Activity> getCurrentActivity(); static boolean mInitialized; static final String APP_STATE_FOREGROUND; static final String APP_STATE_BACKGROUND; static final String APP_STATE_NOTRUNNING; }