Make qt application not stop in background and remove separete thread

This commit is contained in:
Gabriel Calero 2018-05-08 15:45:33 -03:00
parent 03ca427234
commit da69c9d077
5 changed files with 26 additions and 25 deletions

View file

@ -130,15 +130,13 @@ public class InterfaceActivity extends QtActivity {
if (!isLoading) { if (!isLoading) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
} }
// TODO Fix displayPlugin deactivate so it doesn't leave us with a black screen Interface nativeEnterForeground();
//nativeEnterForeground();
} }
@Override @Override
protected void onStop() { protected void onStop() {
super.onStop(); super.onStop();
// TODO Fix displayPlugin deactivate so it doesn't leave us with a black screen Interface nativeEnterBackground();
//nativeEnterBackground();
} }
@Override @Override

View file

@ -504,7 +504,7 @@ public class QtActivity extends Activity {
// GC: this trick allow us to show a splash activity until Qt app finishes // GC: this trick allow us to show a splash activity until Qt app finishes
// loading // loading
if (!isLoading) { if (!isLoading) {
QtApplication.invokeDelegate(); //QtApplication.invokeDelegate();
} }
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
@ -644,7 +644,7 @@ public class QtActivity extends Activity {
@Override @Override
protected void onStop() { protected void onStop() {
super.onStop(); super.onStop();
QtApplication.invokeDelegate(); //QtApplication.invokeDelegate();
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------

View file

@ -14,22 +14,13 @@
AndroidHelper::AndroidHelper() : AndroidHelper::AndroidHelper() :
_accountManager () _accountManager ()
{ {
workerThread.start();
} }
AndroidHelper::~AndroidHelper() { AndroidHelper::~AndroidHelper() {
workerThread.quit();
workerThread.wait();
} }
QSharedPointer<AccountManager> AndroidHelper::getAccountManager() { QSharedPointer<AccountManager> AndroidHelper::getAccountManager() {
return DependencyManager::get<AccountManager>();
_accountManager = QSharedPointer<AccountManager>(new AccountManager, &QObject::deleteLater);
_accountManager->setIsAgent(true);
_accountManager->setAuthURL(NetworkingConstants::METAVERSE_SERVER_URL());
_accountManager->moveToThread(&workerThread);
return _accountManager;
} }
void AndroidHelper::requestActivity(const QString &activityName) { void AndroidHelper::requestActivity(const QString &activityName) {
@ -46,4 +37,12 @@ void AndroidHelper::goBackFromAndroidActivity() {
void AndroidHelper::notifyLoginComplete(bool success) { void AndroidHelper::notifyLoginComplete(bool success) {
emit loginComplete(success); emit loginComplete(success);
} }
void AndroidHelper::setInBackground(bool background) {
inBackground = background;
}
bool AndroidHelper::isInBackground() {
return inBackground;
}

View file

@ -26,6 +26,8 @@ public:
void requestActivity(const QString &activityName); void requestActivity(const QString &activityName);
void notifyLoadComplete(); void notifyLoadComplete();
void goBackFromAndroidActivity(); void goBackFromAndroidActivity();
void setInBackground(bool background);
bool isInBackground();
void notifyLoginComplete(bool success); void notifyLoginComplete(bool success);
@ -44,7 +46,7 @@ private:
AndroidHelper(); AndroidHelper();
~AndroidHelper(); ~AndroidHelper();
QSharedPointer<AccountManager> _accountManager; QSharedPointer<AccountManager> _accountManager;
QThread workerThread; bool inBackground;
}; };
#endif #endif

View file

@ -4331,6 +4331,12 @@ void setupCpuMonitorThread() {
void Application::idle() { void Application::idle() {
PerformanceTimer perfTimer("idle"); PerformanceTimer perfTimer("idle");
#if defined(Q_OS_ANDROID)
if (AndroidHelper::instance().isInBackground()) {
return;
}
#endif
// Update the deadlock watchdog // Update the deadlock watchdog
updateHeartbeat(); updateHeartbeat();
@ -8177,17 +8183,13 @@ void Application::openAndroidActivity(const QString& activityName) {
void Application::enterBackground() { void Application::enterBackground() {
QMetaObject::invokeMethod(DependencyManager::get<AudioClient>().data(), QMetaObject::invokeMethod(DependencyManager::get<AudioClient>().data(),
"stop", Qt::BlockingQueuedConnection); "stop", Qt::BlockingQueuedConnection);
//GC: commenting it out until we fix it AndroidHelper::instance().setInBackground(true);
//getActiveDisplayPlugin()->deactivate();
} }
void Application::enterForeground() { void Application::enterForeground() {
QMetaObject::invokeMethod(DependencyManager::get<AudioClient>().data(), QMetaObject::invokeMethod(DependencyManager::get<AudioClient>().data(),
"start", Qt::BlockingQueuedConnection); "start", Qt::BlockingQueuedConnection);
//GC: commenting it out until we fix it AndroidHelper::instance().setInBackground(false);
/*if (!getActiveDisplayPlugin() || !getActiveDisplayPlugin()->activate()) {
qWarning() << "Could not re-activate display plugin";
}*/
} }
#endif #endif