我希望在Xamarin Forms页面的OnSleep事件中保存当前导航堆栈,并在OnResume事件上恢复它。是否有可能做到这一点?
干杯!
答案 0 :(得分:2)
我认为你不应该记住所有的导航堆栈。您的设备决定终止您的应用或从后台出现的最后一页重新启动。我想你可以记住,如果你是"登录"与否:如果你是"登录"您可以从第一页重新开始"登录后#34;否则从登录"开始#34;
在这种情况下,您可以查看this link并使用Properties
public class App : Xamarin.Forms.Application
{
public App ()
{
}
protected override void OnStart()
{
// Handle when your app starts
Debug.WriteLine ("OnStart");
checkLogin();
}
protected override void OnSleep()
{
// Handle when your app sleeps
Debug.WriteLine ("OnSleep");
}
protected override void OnResume()
{
// Handle when your app resumes
Debug.WriteLine ("OnResume");
checkLogin();
}
}
void checkLogin(){
if (Application.Current.Properties.ContainsKey("IsLogged"))
{
var IsLogged = Application.Current.Properties ["IsLogged"] as bool;
// do something with IsLogged
if(IsLogged)
MainPage = new MyFirstPage();
else
MainPage = new MyLoginPage();
}
else
MainPage = new MyLoginPage();
}
然后,当您已登录
Application.Current.Properties ["IsLogged"] = true;