AppStateManager { public void onActivityResumed(Activity activity) { try { mCurrentActivityName = AppStateManager.getActivityName(activity); int interruptions = mInterruptionCount.get(); if (!mInitialized || !getSession().isActive()) { mInterruptionCount = new AtomicInteger(0); } String previousSessionPackage = null; String previousSessionUri = null; String previousSessionParameters = null; if (activity != null){ ComponentName callingApplication = activity.getCallingActivity(); if (callingApplication != null) { previousSessionPackage = callingApplication.getPackageName(); } if(activity.getIntent() != null) { previousSessionUri = activity.getIntent().getDataString(); if (mLaunchUri == null) { mLaunchUri = activity.getIntent().getData(); } if (mLaunchAction == null) { mLaunchAction = activity.getIntent().getAction(); } if (activity.getIntent().getExtras() != null && activity.getIntent().getExtras().getBundle(Constants.External.APPLINK_KEY) != null) { JSONObject parameters = new JSONObject(); try { parameters.put(Constants.External.APPLINK_KEY, MPUtility.wrapExtras(activity.getIntent().getExtras().getBundle(Constants.External.APPLINK_KEY))); } catch (Exception e) { } previousSessionParameters = parameters.toString(); } } } mCurrentSession.updateBackgroundTime(mLastStoppedTime, getTime()); boolean isBackToForeground = false; if (!mInitialized) { initialize(mCurrentActivityName, previousSessionUri, previousSessionParameters, previousSessionPackage); } else if (isBackgrounded() && mLastStoppedTime.get() > 0) { isBackToForeground = true; mMessageManager.postToMessageThread(new CheckAdIdRunnable()); logStateTransition(Constants.StateTransitionType.STATE_TRANS_FORE, mCurrentActivityName, mLastStoppedTime.get() - mLastForegroundTime, getTime() - mLastStoppedTime.get(), previousSessionUri, previousSessionParameters, previousSessionPackage, interruptions); } mLastForegroundTime = getTime(); if (mCurrentActivityReference != null) { mCurrentActivityReference.clear(); mCurrentActivityReference = null; } mCurrentActivityReference = new WeakReference<Activity>(activity); if (MParticle.getInstance().isAutoTrackingEnabled()) { MParticle.getInstance().logScreen(mCurrentActivityName); } if (isBackToForeground) { MParticle.getInstance().Internal().getKitManager().onApplicationForeground(); Logger.debug("App foregrounded."); } MParticle.getInstance().Internal().getKitManager().onActivityResumed(activity); }catch (Exception e){ Logger.verbose("Failed while trying to track activity resume: " + 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; }
@Test public void testOnActivityResumed() throws Exception { assertEquals(true, manager.isBackgrounded()); manager.onActivityResumed(activity); assertTrue(manager.mInitialized); assertEquals(false, manager.isBackgrounded()); manager.onActivityResumed(activity); }