这是一个解决Android的第二套页面问题。创建第二个界面,而不是使用现有活动的设置页面启动新活动的OnCreate,其中新活动的OnCreate调用设置页面并完成当前活动。
App.cs
public static ILoginManager LoginManager;
public static IAppNavigation SplashManger;
public static Page GetLoginPage(ILoginManager lmanager)
{
LoginManager = lmanager;
return new Page_Login();
}
public static Page GetShowSplashPage(IAppNavigation iSplashNavigation)
{
SplashManger = iSplashNavigation;
return new Page_Splash();
}
的Android MainActivty
[Activity(Label = "", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : AndroidActivity, IAppNavigation
{
protected override void OnCreate(Bundle bundle)
{
//Window.RequestFeature(WindowFeatures.NoTitle);
base.OnCreate(bundle);
Xamarin.Forms.Forms.Init(this, bundle);
SetPage(App.GetShowSplashPage(this));
}
public void GetLoginPage()
{
StartActivity(new Intent(this, typeof(LoginActivity)));
Finish();
}
的Android LoginActivity
[Activity(Label = "", ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class LoginActivity : AndroidActivity, ILoginManager
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
Xamarin.Forms.Forms.Init(this, bundle);
SetPage(App.GetLoginPage(this));
}
public void GetMainMenu()
{
StartActivity(new Intent(this, typeof(MainMenuActivity)));
Finish();
}
在你的iOS不需要做任何特别的事情,只需实现你将要在App委托中使用的所有必要的接口。
的iOS的AppDelegate
[Register("AppDelegate")]
public partial class AppDelegate : UIApplicationDelegate, ILoginManager, IAppNavigation
{
// class-level declarations
UIWindow window;
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
Forms.Init();
window = new UIWindow(UIScreen.MainScreen.Bounds);
window.RootViewController = App.GetShowSplashPage(this).CreateViewController();
window.MakeKeyAndVisible();
return true;
}
public void GetMainMenu()
{
window.RootViewController = App.GetMainMenu().CreateViewController();
window.MakeKeyAndVisible();
}
public void GetLoginPage()
{
window.RootViewController = App.GetLoginPage(this).CreateViewController();
window.MakeKeyAndVisible();
}
的Xamarin.Forms框架处理导航为您服务。您应该使用Xamarin.Forms.Navigation类来管理导航堆栈,并避免在Android项目中使用SetPage, – 2016-12-28 18:47:19