Navigate to a page when getting back to app

Shiva799Shiva799 Member ✭✭

Hi All,
I have an issue with navigation. When I click home screen button of device and get back to app I get app homescreen instead of pin page. Ideally it should show pin page and its working fine with back button of device.
OnStart() method has navigationasync but the same is not working with OnResume() method.
Do I have to go to each of the Platform project cs file and add the navigation there like for Android OnRestart() method?
If anyone knows the solution please let me know

Thanks

Answers

  • Dinesh_OfficialDinesh_Official Member ✭✭✭

    @Shiva799 ,

    Need to clear the Navigation history and then navigate to the required page as like below code example.

    `
    protected override async void OnResume ()
    {
    var navigation = MainPage.Navigation;

    // Clear the stack history first//
    await navigation .PopToRootAsync (true);
    
    // And then open the required page 
    await navigation .PushAsync(new PinPage());
    

    }`

  • Shiva799Shiva799 Member ✭✭

    the code is in prism so it doesnt accept pushasync in android code. i tried adding navigation in individual platforms cs files but its not working. anyother solution?

  • soufianemarlysoufianemarly Member ✭✭

    you can use

    MessagingCenter.Send(Xamarin.Forms.Application.Current, "goToPage", new newpage());

  • Shiva799Shiva799 Member ✭✭

    i tried it like this as per ur suggestion
    //TODO: Start mode work
    protected override void OnStart()
    {
    SetCultureInfo();
    CrossSettings.Current.AddOrUpdateValue(Keys.IsLoggedIn, false);
    NavigationService.NavigateAsync("Launcher");
    MessagingCenter.Subscribe(NavigationService, "LaunchApp",(sender)=> {
    NavigationService.NavigateAsync("Launcher");
    });
    }

        // TODO: Sleep mode work
        /// <summary>
        /// Store intermediate form edit and save while sleep mode and bring back once Resume
        /// </summary>
        protected override void OnSleep()
        {
            MessagingCenter.Send<INavigationService>(NavigationService,"LaunchApp");
            base.OnSleep();
            MessagingCenter.Unsubscribe<INavigationService>(NavigationService, "LaunchApp");
        }
        protected override void OnResume()
        {
            MessagingCenter.Subscribe<INavigationService>(NavigationService, "LaunchApp", (sender) => {
                NavigationService.NavigateAsync("Launcher");
            });
            MessagingCenter.Send<INavigationService>(NavigationService, "LaunchApp");
            base.OnResume();
        }
    

    but it didnt work

Sign In or Register to comment.