這是一個解決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