public static synchronized void engage ( final Context context , final String event , final BooleanCallback callback , final Map < String , Object > customData , final ExtendedData ... extendedData ) { if ( context == null ) { throw new IllegalArgumentException ( "Context is null" ) ; } if ( StringUtils . isNullOrEmpty ( event ) ) { throw new IllegalArgumentException ( "Event is null or empty" ) ; } // first, we check if there's an engagement callback to inject final OnPreInteractionListener preInteractionListener = Apptentive . preInteractionListener ; // capture variable to avoid concurrency issues if ( preInteractionListener != null ) { dispatchConversationTask ( new ConversationDispatchTask ( callback , DispatchQueue . mainQueue ( ) ) { @ Override protected boolean execute ( Conversation conversation ) { if ( ! canShowLocalAppInteraction ( conversation , event ) ) { return false ; } boolean allowsInteraction = preInteractionListener . shouldEngageInteraction ( event , customData ) ; ApptentiveLog . i ( "Engagement callback allows interaction for event '%s': %b" , event , allowsInteraction ) ; if ( ! allowsInteraction ) { return false ; } return engageLocalAppEvent ( context , conversation , event , customData , extendedData ) ; // actually engage event } } , StringUtils . format ( "engage '%s' event" , event ) ) ; return ; } dispatchConversationTask ( new ConversationDispatchTask ( callback , DispatchQueue . mainQueue ( ) ) { @ Override protected boolean execute ( Conversation conversation ) { return engageLocalAppEvent ( context , conversation , event , customData , extendedData ) ; } } , StringUtils . format ( "engage '%s' event" , event ) ) ; }
This method takes a unique event string stores a record of that event having been visited determines if there is an interaction that is able to run for this event and then runs it . If more than one interaction can run then the most appropriate interaction takes precedence . Only one interaction at most will run per invocation of this method .