Skip to content

Commit 3fbedf1

Browse files
committed
Fix NPEs when in-apps are resized while the app is in background
1 parent f9f81aa commit 3fbedf1

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

iterableapi/src/main/java/com/iterable/iterableapi/IterableInAppHTMLNotification.java

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.iterable.iterableapi;
22

3+
import android.app.Activity;
34
import android.app.Dialog;
45
import android.content.Context;
56
import android.graphics.Color;
@@ -178,15 +179,20 @@ protected void onStop() {
178179
*/
179180
@JavascriptInterface
180181
public void resize(final float height) {
181-
getOwnerActivity().runOnUiThread(new Runnable() {
182+
final Activity activity = getOwnerActivity();
183+
if (activity == null) {
184+
return;
185+
}
186+
187+
activity.runOnUiThread(new Runnable() {
182188
@Override
183189
public void run() {
184190
// Since this is run asynchronously, notification might've been dismissed already
185-
if (notification == null) {
191+
if (notification == null || notification.getWindow() == null) {
186192
return;
187193
}
188194

189-
DisplayMetrics displayMetrics = getOwnerActivity().getResources().getDisplayMetrics();
195+
DisplayMetrics displayMetrics = activity.getResources().getDisplayMetrics();
190196
Window window = notification.getWindow();
191197
Rect insetPadding = notification.insetPadding;
192198

0 commit comments

Comments
 (0)