[android] enter foreground and background are corrected

This commit is contained in:
Arsentiy Milchakov 2019-06-25 18:57:43 +03:00 committed by Roman Kuznetsov
parent cbd57660d1
commit b07cb62333
3 changed files with 18 additions and 4 deletions

View file

@ -304,7 +304,6 @@ void Framework::DetachSurface(bool destroySurface)
{
LOG(LINFO, ("Destroy surface."));
m_isSurfaceDestroyed = true;
m_work.EnterBackground();
m_work.OnDestroySurface();
}
@ -378,8 +377,6 @@ bool Framework::AttachSurface(JNIEnv * env, jobject jSurface)
bool const recreateContextDependentResources = (m_vulkanContextFactory == nullptr);
m_work.OnRecoverSurface(w, h, recreateContextDependentResources);
m_isSurfaceDestroyed = false;
m_work.EnterForeground();
}
LOG(LINFO, ("Attach surface finished."));

View file

@ -45,4 +45,13 @@ extern "C"
g_framework->AddString(jni::ToNativeString(env, name),
jni::ToNativeString(env, value));
}
JNIEXPORT void JNICALL
Java_com_mapswithme_maps_MwmApplication_nativeOnTransit(JNIEnv *, jclass, jboolean foreground)
{
if (static_cast<bool>(foreground))
g_framework->NativeFramework()->EnterForeground();
else
g_framework->NativeFramework()->EnterBackground();
}
}

View file

@ -45,7 +45,7 @@ import com.mapswithme.util.statistics.Statistics;
import java.util.HashMap;
import java.util.List;
public class MwmApplication extends Application
public class MwmApplication extends Application implements AppBackgroundTracker.OnTransitionListener
{
@SuppressWarnings("NullableProblems")
@NonNull
@ -280,6 +280,7 @@ public class MwmApplication extends Application
TrafficManager.INSTANCE.initialize();
SubwayManager.from(this).initialize();
mPurchaseOperationObservable.initialize();
mBackgroundTracker.addListener(this);
mFrameworkInitialized = true;
}
@ -379,6 +380,7 @@ public class MwmApplication extends Application
private static native void nativeInitFramework();
private static native void nativeProcessTask(long taskPointer);
private static native void nativeAddLocalization(String name, String value);
private static native void nativeOnTransit(boolean foreground);
@NonNull
public Logger getLogger()
@ -396,6 +398,12 @@ public class MwmApplication extends Application
return mFirstLaunch;
}
@Override
public void onTransit(boolean foreground)
{
nativeOnTransit(foreground);
}
private static class VisibleAppLaunchListener implements AppBackgroundTracker.OnVisibleAppLaunchListener
{
@Override