设备屏幕旋转时是否有任何方法被调用?是否在Android中删除和恢复数据?
当屏幕旋转时,Android应用程序将被销毁并重新启动。要在轮换期间保持其状态,您需要致电:
onSaveInstanceState()
onRestoreInstanceState()
Windows 10 Universal App在设备轮换期间是否具有存储会话状态?
答案 0 :(得分:0)
我知道这已经过时了,你可能已经转移到别的东西上了。对于遇到这个问题的其他人(就像我一样),答案是:是的,有一种方法。是的,外观就像存储和检索数据一样,系统会处理您的' Bundle'对你而言。
在App.xaml.cs文件中有一个方法:
/// <summary>
/// Invoked when application execution is being suspended. Application state is saved
/// without knowing whether the application will be terminated or resumed with the contents
/// of memory still intact.
/// </summary>
/// <param name="sender">The source of the suspend request.</param>
/// <param name="e">Details about the suspend request.</param>
private void OnSuspending(object sender, SuspendingEventArgs e)
{
var deferral = e.SuspendingOperation.GetDeferral();
//TODO: Save application state and stop any background activity
deferral.Complete();
}
这可以为您保存状态。这是有道理的,我的Windows手机会在上次点击主屏幕时返回按钮。如果我从应用程序转到应用程序,后退按钮会返回每个应用程序,保留我离开的位置。
当我在窗口上放置TextBlock并使用按钮更改文本时,文本在旋转后仍保持更改状态。在我按下按钮后,它实际上仍然有变化。或者&#39; home&#39;在应用程序之外。保持国家似乎不是一个问题,失去它可能是。 (我将记得从现在开始重置&#39;重置&#39;按钮或方法!)
OnSuspending()
在sealed partial class App : Application
中定义,密封意味着您无法对其进行扩展,因此您也无法覆盖OnSuspending()
。