I have enabled Firebase In-App messaging for my android app. When i am testing In-App Messaging it is showing in SplashActivity of the app.
Note: SplashActivity just have runnable to get delay of 3 seconds. LoginActivity have some functions to check wheter shared preferences are not null.
I tried to add in onCreate() this below line of code:
FirebaseInAppMessaging.getInstance().setMessagesSuppressed(true)
And FirebaseInAppMessaging.getInstance().setMessagesSuppressed(false)
in onDestroy()
I want this messsage to show in MainActivity.
Firebase in-app messaging is triggered by analytical events.
if you want show message in MainActivity ->
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
...
FirebaseAnalytics.getInstance(this).logEvent("main_activity_ready",null)
//or
//FirebaseInAppMessaging.getInstance().triggerEvent("main_activity_ready");
}
}
and select this event in firebase console.
Use below method to "Start" and "Stop" InAppMessaging in different Activities.
public static void inAppMessagingInitialization(Context context, boolean setSuppressed,String eventName){ //setSuppressed false means start getting message
FirebaseInAppMessaging.getInstance().setMessagesSuppressed(setSuppressed); //true==Stop inAppMessaging
if (!eventName.equals("")){
FirebaseAnalytics.getInstance(context).logEvent(eventName,null); //To Show InAppMessage in MainActivity. Need to add this event name in Web console campaign
FirebaseInAppMessaging.getInstance().triggerEvent(eventName);
}
}
If you don't want show in SplashActivity, then call above method like below:
inAppMessagingInitialization(context,true,""); //Stops inAppMessaging
To show InAppMessage in MainActivity call above method like below and set event name in InAppMessaging console.
inAppMessagingInitialization(context,false,"main_activity_inappmessaging"); //Starts inAppMessaging
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With