I create new mobile app using xamarin form. I have to create two pages login screen and home screen. I get sample from Here
But when i create same I cant go second page. it always stay login page only.
In my android MainActivity code
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
}
setPage method called second time but page content not replaced. Please help any one
Here is a work around to the second set page problem with Android. Create a second interface and instead of using set page on the existing activity start a new activity where OnCreate of the new activity calls set page and finish 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 special just implement all necessary interfaces you are going to use in App delegate.
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();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.