简体   繁体   中英

How to terminate windows phone 8.1 app

I want to exit my app when the user press back button. I have used Hardware Pressed events to navigate between pages. When I navigated to the first page where no Hardware Button press event is used and press back button it goes back to the Menu Screen and not getting terminated as shown in image

在此处输入图片说明

Need help.

I also faced the same problem but by using the following piece of code

Application.Current.Exit()

the application shuts down properly.

This is generally not recommended. Think hard about why you want to do this and if it really makes sense. Barring recovering from a failure it usually doesn't. The expected behavior is for the app to work nicely with the process lifetime code. There is typically no downside to keeping the app suspended, and it is much more efficient to resume from suspension than to restart completely. The user can use the built-in options to explicitly close the app if desired.

That said, you can call Windows.UI.Xaml.Application.Exit .

You can use this snippet to make the back button react the same as WP8 on WP8.1. In public App() :

#if WINDOWS_PHONE_APP
HardwareButtons.BackPressed += HardwareButtons_BackPressed;
#endif

and in the same scope as App() :

#if WINDOWS_PHONE_APP
void HardwareButtons_BackPressed(object sender, BackPressedEventArgs e)
{
    Frame rootFrame = Window.Current.Content as Frame;

    if (rootFrame != null && rootFrame.CanGoBack)
    {
        e.Handled = true;
        rootFrame.GoBack();
    }
}
#endif

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM