保存区域说明暂停应用程序
问题描述:
我正在研究Google Tango应用程序,我一直试图使用TangoApplication
类保存区域说明。保存区域说明暂停应用程序
我现在有呼吁OnApplicationPause()
事件
private void DoSaveCurrentAreaDescription(bool forceLearningMode)
{
// Disable interaction before saving.
m_initialized = false;
if (m_tangoApplication.m_areaDescriptionLearningMode)
{
// The keyboard is not readable if you are not in the Unity main thread. Cache the value here.
string name = "config";
// Start saving process in another thread.
m_saveThread = new Thread(delegate()
{
// Start saving process in another thread.
m_curAreaDescription = AreaDescription.SaveCurrent();
AreaDescription.Metadata metadata = m_curAreaDescription.GetMetadata();
metadata.m_name = name;
m_curAreaDescription.SaveMetadata(metadata);
m_TangoManager.m_lastKnownAreaDescription = m_curAreaDescription;
m_TangoManager.SaveProductLocationsToDisk();
});
m_saveThread.Start();
}
else
{
m_TangoManager.SaveProductLocationsToDisk();
}
}
此获取应用程序暂停功能中调用,但它不允许我保存ADF下面的函数。如果我在应用程序仍在运行时调用此函数,它将被保存。
如果任何人有任何想法会发生什么(我假设线程问题与背后的过程)我会永远在你的债务。
答
有两个可能的原因是它不保存:
.Exception是由Unity抛出。
如果探戈AreaDescription
或SaveProductLocationsToDisk
API使用任何统一的API,然后这就是问题所在,因为你can't使用统一的API在另一个线程和异常会被抛出,如果你尝试这样做。
您可以检查,如果这是通过将保存代码里面try catch
块的问题,然后从的Android监视器在Android Studio中查看结果。
的解决方法是删除Thread
代码,并确保保存代码运行在主Thread
private void DoSaveCurrentAreaDescription(bool forceLearningMode)
{
// Disable interaction before saving.
m_initialized = false;
if (m_tangoApplication.m_areaDescriptionLearningMode)
{
//The keyboard is not readable if you are not in the Unity main thread. Cache the value here.
string name = "config";
//Start saving process in another thread.
m_curAreaDescription = AreaDescription.SaveCurrent();
AreaDescription.Metadata metadata = m_curAreaDescription.GetMetadata();
metadata.m_name = name;
m_curAreaDescription.SaveMetadata(metadata);
m_TangoManager.m_lastKnownAreaDescription = m_curAreaDescription;
m_TangoManager.SaveProductLocationsToDisk();
}
else
{
m_TangoManager.SaveProductLocationsToDisk();
}
}
。它不是节能,因为它是做保存之前的应用程序正在退出。
解决方案是在代码的末尾添加m_saveThread.Join();
,以便Unity在等待代码执行之前执行。
private void DoSaveCurrentAreaDescription(bool forceLearningMode)
{
// Disable interaction before saving.
m_initialized = false;
if (m_tangoApplication.m_areaDescriptionLearningMode)
{
// The keyboard is not readable if you are not in the Unity main thread. Cache the value here.
string name = "config";
// Start saving process in another thread.
m_saveThread = new Thread(delegate()
{
// Start saving process in another thread.
m_curAreaDescription = AreaDescription.SaveCurrent();
AreaDescription.Metadata metadata = m_curAreaDescription.GetMetadata();
metadata.m_name = name;
m_curAreaDescription.SaveMetadata(metadata);
m_TangoManager.m_lastKnownAreaDescription = m_curAreaDescription;
m_TangoManager.SaveProductLocationsToDisk();
});
m_saveThread.Start();
//Wait for Save to finish before existing from app
m_saveThread.Join();
}
else
{
m_TangoManager.SaveProductLocationsToDisk();
}
}
或再次,删除Thread
代码,并确保保存代码运行在主Thread
就像我们在#1一样。
答
这实际上是由于探戈的生命周期暂停和卸载了所有探戈资源之后,我的暂停功能才有机会保存它。当前进入后台时,没有真正的方法来调用保存区域描述功能。我还联系了谷歌的工程师,并接受了一个沉重的“不要这样做”,因为目前它没有像Tango那样工作。
在SDK上测试:Hopak