首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Goto主屏幕

Goto主屏幕
EN

Stack Overflow用户
提问于 2014-02-24 06:46:56
回答 1查看 399关注 0票数 0

App流程就是这样;

  1. 用户启动该应用程序,并看到一个写有“后台任务启动”的页面。
  2. 如果用户按回按钮应用程序终止并结束后台任务
  3. 但是如果用户点击菜单按钮并使用其他应用程序,那么我的应用程序就会继续运行。

现在我想到了两个解决方案,请帮助我解决这个问题。

答:我应该有“确定”按钮;如果用户点击它,那么主菜单应该打开B。在后退按钮中写什么,这样应用程序就不会终止。

在app.xaml中

专用静电测定仪;

代码语言:javascript
复制
    public static Geolocator Locator
    {
        get
        {
            lock (typeof(App))
            {
                if (locator == null)
                {
                    locator = new Geolocator();
                    locator.DesiredAccuracy = PositionAccuracy.High;
                    //locator.MovementThreshold = 50;
                    locator.ReportInterval = 10000;
                }
            }
            return locator;
        }
    }

在MainPage.xaml.cs中

保护覆盖无效OnNavigatedTo(NavigationEventArgs e) { App.Locator.PositionChanged += Locator_PositionChanged;}

谢谢

EN

回答 1

Stack Overflow用户

发布于 2014-02-24 07:55:18

最有可能的是,没有办法做到这一点。

您可以重写后退按钮点击事件,但不能覆盖主按钮事件。

此外,您甚至不能以编程方式调用本机home按钮事件。

msdn论坛有一个类似问题的链接

更新.你仍然认为,问题在于后退和菜单按钮。这在我看来是不对的。问题是,当Application_Closing事件被击中时,后台代理没有被激活。

App.xaml.cs中有两种方法:

Application_Deactivated和Application_Closing.如果您的后台任务被执行,您的后台任务应该是活动的。

代码语言:javascript
复制
// Code to execute when the application is deactivated (sent to background, e.g. menu button is hit)
// This code will not execute when the application is closing
private void Application_Deactivated(object sender, DeactivatedEventArgs e)
{

}

// Code to execute when the application is closing (eg, user hit Back)
// This code will not execute when the application is deactivated
private void Application_Closing(object sender, ClosingEventArgs e)
{

}

在后台代理构造函数中设置一个断点,并查看是否已命中。

顺便提一下,对于你的两种解决方案:

解决方案A不能完成。解决方案B可以通过重写OnNavigatedFrom方法来完成。

代码语言:javascript
复制
protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
        {          
            // nothing will happen here
            //base.OnNavigatedFrom(e);
        }

然而,这将是对windows-phone导航服务本机行为的粗暴违反。不会通过认证的。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21980706

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档