OneSignal-Android-SDK icon indicating copy to clipboard operation
OneSignal-Android-SDK copied to clipboard

In-App Message currently works on an Activity level, but should work on an Application level

Open mikechoch opened this issue 4 years ago • 0 comments

Intro

In-App Messages (IAMs) can be problematic during Activity to Activity navigation. This is due to the IAM view being coupled with the Activity-Lifecycle to support orientation changes, resuming/pausing app, etc. The goal was to have the Fullscreen and Center Modal IAMs show above the entire app, until dismissed (excluding outside of the app). Then also have Top and Bottom Banner IAMs show above the app (excluding outside of the app) and allow user interaction with the Activity behind the IAM, until dismissed.

Description

The issue has been known since the release of In-App Messaging in the OneSignal Native Android SDK (Version 3.11.0).

A simple description of the issue comes with understanding the creation of the view holding the IAM. The Android PopupWindow class was used to construct and house the IAM content. A flag controls what views the PopupWindow has priority over or not. Below is a basic snippet that shows how we create our IAM view from the PopupWindow class:

popupWindow = new PopupWindow(contentView, width, height);

PopupWindowCompat.setWindowLayoutType(
    popupWindow,
    WindowManager.LayoutParams.INSERT_FLAG_HERE
);

popupWindow.showAtLocation(parentView, gravity, x, y);

If we replace the INSERT_FLAG_HERE in our code snippet with some of these flags we will see different behavior from our IAM inside of the application. The WindowManager.LayoutParams has a lot of options to pick through and the documentation located in the WindowManager docs.

The current flag is the TYPE_APPLICATION_ATTACHED_DIALOG flag.

The desired flag is the TYPE_SYSTEM_ALERT flag.

TYPE_APPLICATION_ATTACHED_DIALOG vs. TYPE_SYSTEM_ALERT: TYPE_SYSTEM_ALERT is desired because of the app level functionality it offered. The IAM PopupWindow is allowed to sit above all Activity's on the stack when using this flag and won't hide the PopupWindow when navigating through an app's back stack. The issue with this flag is it being deprecated in API 26, which would require handling cases above API 26. In this case, Android introduced a new flag to replace this one and it is called the TYPE_APPLICATION_OVERLAY flag.

TYPE_APPLICATION_OVERLAY: In combo with the deprecated TYPE_SYSTEM_ALERT flag, this should cover all cases, but Android incorporated a permission along side the TYPE_APPLICATION_OVERLAY flag, which would require all apps to include in their AndroidManifest.xml and this is undesirable. This permission is the SYSTEM_ALERT_WINDOW permission.

TYPE_APPLICATION_ATTACHED_DIALOG: Due to the required permission, we settled with the TYPE_APPLICATION_ATTACHED_DIALOG flag. This flag works on an Activity level, and which now brings us to the root issue.

Environment

Android Native SDK 3.11.0+

Future

Unless Android decides to add a new flag offering the in-between functionality we desire for this feature, this will continue to work as it does today. Looking ahead though, enough time with no response or update from Google, we may go down the path of creating our own solution and recycling the IAM each time a Activity is created or destroyed and repeat on new Activity's.

mikechoch avatar Feb 11 '20 01:02 mikechoch