question: public static final boolean inMessagingApp ( Context context ) { ActivityManager mAM = ( ActivityManager ) context . getSystemService ( Context . ACTIVITY_SERVICE ) ; String messagingAppPackageName = null ; if ( hasKitKat ( ) ) { messagingAppPackageName = Sms . getDefaultSmsPackage ( context ) ; } if ( messagingAppPackageName == null ) { messagingAppPackageName = SmsMessageSender . MESSAGING_PACKAGE_NAME ; } final List < RunningTaskInfo > mRunningTaskList = mAM . getRunningTasks ( 1 ) ; final Iterator < RunningTaskInfo > mIterator = mRunningTaskList . iterator ( ) ; RunningTaskInfo mRunningTask ; if ( mIterator . hasNext ( ) ) { mRunningTask = mIterator . next ( ) ; if ( mRunningTask != null ) { final ComponentName runningTaskComponent = mRunningTask . baseActivity ; if ( messagingAppPackageName . equals ( runningTaskComponent . getPackageName ( ) ) ) { return true ; } } } return false ; }
target:  This function will see if the most recent activity was the system messaging app so we can suppress the popup as the user is likely already viewing messages or composing a new message