Xamarin.form installer did not work a second time

I am creating a new mobile application using the xamarin form. I need to create a two page login screen and a home screen. I get a sample from here

But when I create the same, I cannot go to the second page. it always remains only on the login page.

In my Android code MainActivity

public class MainActivity : AndroidActivity, LoginManager { protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); Xamarin.Forms.Forms.Init(this, bundle); SetPage(App.GetLoginPage(this)); // SetPage(App.GetLoginPage(this)); } #region ILoginManager implementation public void ShowMainPage() { SetPage(App.GetHomePage(this)); } public void Logout() { SetPage(App.GetLoginPage(this)); } #endregion } 

The setPage method is called a second time, but the contents of the page are not replaced. Please help anyone

+5
source share
1 answer

Here is the work with the problem of the second page with Android. Create a second interface and instead of using the installed page in an existing activity, start a new activity in which OnCreate of the new action calls the given page and completes the current activity.

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(); } 

In iOS, you do not need to do anything, just implement all the necessary interfaces that you are going to use in the application’s deletion.

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(); } 
0
source

Source: https://habr.com/ru/post/1204420/


All Articles