Android: Make sure we deliver all queued actions when we resume.

When the activity is paused, all runOnUi actions are dropped :(, this
patch ensures that no action is lost no matter what.

Task-number: QTBUG-45526
Change-Id: I61db4f73b0d2da47bf71a1324dc40b90dab01e81
Reviewed-by: Christian Stromme <christian.stromme@theqtcompany.com>
This commit is contained in:
BogDan Vatra 2015-10-16 17:22:14 +03:00
parent 31ef0d0dd6
commit f35797991e
2 changed files with 29 additions and 28 deletions

View File

@ -77,7 +77,6 @@ import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
public class QtActivityDelegate
{
@ -211,10 +210,10 @@ public class QtActivityDelegate
private final int EnterKeyPrevious = 7;
// application state
private final int ApplicationSuspended = 0x0;
private final int ApplicationHidden = 0x1;
private final int ApplicationInactive = 0x2;
private final int ApplicationActive = 0x4;
public static final int ApplicationSuspended = 0x0;
public static final int ApplicationHidden = 0x1;
public static final int ApplicationInactive = 0x2;
public static final int ApplicationActive = 0x4;
public boolean setKeyboardVisibility(boolean visibility, long timeStamp)
@ -902,26 +901,17 @@ public class QtActivityDelegate
public void onPause()
{
QtNative.updateApplicationState(ApplicationInactive);
QtNative.setApplicationState(ApplicationInactive);
}
public void onResume()
{
// fire all lostActions
synchronized (QtNative.m_mainActivityMutex)
{
Iterator<Runnable> itr = QtNative.getLostActions().iterator();
while (itr.hasNext())
m_activity.runOnUiThread(itr.next());
QtNative.updateApplicationState(ApplicationActive);
QtNative.setApplicationState(ApplicationActive);
if (m_started) {
QtNative.clearLostActions();
QtNative.updateWindow();
updateFullScreen(); // Suspending the app clears the immersive mode, so we need to set it again.
}
}
}
public void onNewIntent(Intent data)
{
@ -942,7 +932,7 @@ public class QtActivityDelegate
public void onStop()
{
QtNative.updateApplicationState(ApplicationSuspended);
QtNative.setApplicationState(ApplicationSuspended);
}
public Object onRetainNonConfigurationInstance()

View File

@ -55,6 +55,7 @@ import android.view.View;
import java.security.KeyStore;
import java.security.cert.X509Certificate;
import java.util.Iterator;
import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
@ -62,6 +63,7 @@ import javax.net.ssl.X509TrustManager;
public class QtNative
{
private static Activity m_activity = null;
private static boolean m_activityPaused = false;
private static QtActivityDelegate m_activityDelegate = null;
public static Object m_mainActivityMutex = new Object(); // mutex used to synchronize runnable operations
@ -166,14 +168,23 @@ public class QtNative
}
}
static public ArrayList<Runnable> getLostActions()
{
return m_lostActions;
}
static public void clearLostActions()
public static void setApplicationState(int state)
{
synchronized (m_mainActivityMutex) {
switch (state) {
case QtActivityDelegate.ApplicationActive:
m_activityPaused = false;
Iterator<Runnable> itr = m_lostActions.iterator();
while (itr.hasNext())
runAction(itr.next());
m_lostActions.clear();
break;
default:
m_activityPaused = true;
break;
}
}
updateApplicationState(state);
}
private static void runAction(Runnable action)
@ -181,7 +192,7 @@ public class QtNative
synchronized (m_mainActivityMutex) {
final Looper mainLooper = Looper.getMainLooper();
final Handler handler = new Handler(mainLooper);
final boolean actionIsQueued = m_activity != null && mainLooper != null && handler.post(action);
final boolean actionIsQueued = !m_activityPaused && m_activity != null && mainLooper != null && handler.post(action);
if (!actionIsQueued)
m_lostActions.add(action);
}