diff --git a/android/jni/com/mapswithme/platform/Platform.cpp b/android/jni/com/mapswithme/platform/Platform.cpp index 56c61df873..bc327c46eb 100644 --- a/android/jni/com/mapswithme/platform/Platform.cpp +++ b/android/jni/com/mapswithme/platform/Platform.cpp @@ -206,10 +206,8 @@ namespace android return; JNIEnv * env = jni::GetEnv(); - if (env == nullptr) - return; - - env->CallVoidMethod(m_functorProcessObject, m_sendPushWooshTagsMethod, jni::ToJavaString(env, tag), + env->CallVoidMethod(m_functorProcessObject, m_sendPushWooshTagsMethod, + jni::TScopedLocalRef(env, jni::ToJavaString(env, tag)).get(), jni::TScopedLocalObjectArrayRef(env, jni::ToJavaStringArray(env, values)).get()); } } // namespace android diff --git a/android/src/com/mapswithme/util/statistics/PushwooshHelper.java b/android/src/com/mapswithme/util/statistics/PushwooshHelper.java index 55cbb9a980..bf4f27deb5 100644 --- a/android/src/com/mapswithme/util/statistics/PushwooshHelper.java +++ b/android/src/com/mapswithme/util/statistics/PushwooshHelper.java @@ -10,6 +10,7 @@ import com.mapswithme.maps.Framework; import com.pushwoosh.PushManager; import com.pushwoosh.SendPushTagsCallBack; +import java.lang.ref.WeakReference; import java.util.HashMap; import java.util.LinkedList; import java.util.List; @@ -22,7 +23,8 @@ public final class PushwooshHelper implements SendPushTagsCallBack private static final PushwooshHelper sInstance = new PushwooshHelper(); - private Context mContext; + private WeakReference mContext; + private final Object mSyncObject = new Object(); private AsyncTask mTask; private List> mTagsQueue = new LinkedList<>(); @@ -35,7 +37,7 @@ public final class PushwooshHelper implements SendPushTagsCallBack { synchronized (mSyncObject) { - mContext = context; + mContext = new WeakReference<>(context); } } @@ -85,7 +87,11 @@ public final class PushwooshHelper implements SendPushTagsCallBack @Override protected Void doInBackground(Void... params) { - PushManager.sendTags(mContext, tagsToSend, PushwooshHelper.this); + final Context context = mContext.get(); + if (context == null) + return null; + + PushManager.sendTags(context, tagsToSend, PushwooshHelper.this); return null; } };