2015-01-14 4 views
1

내 응용 프로그램은 보조 타일을 고정하여 응용 프로그램을 시작하는 데 사용할 수 있습니다. 내가 달성하기 위해 노력하고 행동은 이것이다 : -Windows Phone 8.1 - Exit() 메서드가 작동하지 않습니다.

  • 응용 프로그램이 이미 보조 타일을 클릭하면 실행중인 경우, 그것은 URI를 시작 앱이 때 실행되지 않은 경우
  • 를 실행하는 응용 프로그램을 잎 보조 타일을 클릭하면 URI를 시작한 다음 Exit() 메소드를 호출하여 앱을 종료합니다 (사용자가 앱 전환보기에 추가 앱을 표시하지 않도록).

아래와 같이 app.xaml.cs의 OnLaunched()에서이 작업을 수행하는 데 사용하는 코드입니다.

protected override void OnLaunched(LaunchActivatedEventArgs e) 
    { 
#if DEBUG 
     if (System.Diagnostics.Debugger.IsAttached) 
     { 
      this.DebugSettings.EnableFrameRateCounter = true; 
     } 
#endif 

     // Check to see if app has been launched from a secondary tile 
     if (e.Kind==ActivationKind.Launch && e.TileId != "App") 
     { 
      //If so then launch Uri passed from tile 
      var uri = new Uri(e.Arguments); 
      Windows.System.Launcher.LaunchUriAsync(uri); 

      //If launched from a secondary tile, then close the app if it wasn't already running 
      if (e.PreviousExecutionState == ApplicationExecutionState.NotRunning) 
      { 
       Exit(); 
      } 


     } 

     Frame rootFrame = Window.Current.Content as Frame; 

     // Do not repeat app initialization when the Window already has content, 
     // just ensure that the window is active 
     if (rootFrame == null) 
     { 
      // Create a Frame to act as the navigation context and navigate to the first page 
      rootFrame = new Frame(); 

      // TODO: change this value to a cache size that is appropriate for your application 
      rootFrame.CacheSize = 1; 

      if (e.PreviousExecutionState == ApplicationExecutionState.Terminated) 
      { 
       // TODO: Load state from previously suspended application 
      } 

      // Place the frame in the current Window 
      Window.Current.Content = rootFrame; 
     } 

     if (rootFrame.Content == null) 
     { 
      // Removes the turnstile navigation for startup. 
      if (rootFrame.ContentTransitions != null) 
      { 
       this.transitions = new TransitionCollection(); 
       foreach (var c in rootFrame.ContentTransitions) 
       { 
        this.transitions.Add(c); 
       } 
      } 

      rootFrame.ContentTransitions = null; 
      rootFrame.Navigated += this.RootFrame_FirstNavigated; 

      // When the navigation stack isn't restored navigate to the first page, 
      // configuring the new page by passing required information as a navigation 
      // parameter 
      if (!rootFrame.Navigate(typeof(SignInPage), e.Arguments)) 
      { 
       throw new Exception("Failed to create initial page"); 
      } 
     } 

     // Ensure the current window is active 
     Window.Current.Activate(); 
    } 

에뮬레이터에서 실행할 때 필요에 따라 정확하게 작동합니다. 그러나 내 장치 (Nokia 925)에서 실행하면 보조 타일에서 실행될 때 앱이 종료되지 않으므로 이전에 실행되지 않았더라도 항상 앱 전환 창이 나타납니다.

EDIT OnLaunched()에서 Exit() 메서드를 호출하면 올바르게 종료되고 올바르게 종료됩니다. 난 단지가 있다고 가정 할 수있는 응용 프로그램이 그 작동하지 않는 실행되고, 따라서 종료()를 호출되어 있는지 여부를 확인 '경우'

if (e.PreviousExecutionState == ApplicationExecutionState.NotRunning) 

무슨 일이 일어나고 있는지 모든 아이디어를 어떻게 얻을 수있는 에뮬레이터처럼 행동하는 전화?

+0

Lumia 1520에서 실행중인 응용 프로그램의 OnLaunched 이벤트 처리기에서 Exit() 메서드를 호출하고 응용 프로그램이 종료되었습니다. –

+0

방금 ​​Exit() 메서드를 호출 해봤는데 작동했습니다. 그것처럼 보인다 if (e.PreviousExecutionState == ApplicationExecutionState.NotRunning) 그때 작동하지 않는 논리 .... 이상. – smb1973

+0

내 의견이 도움이 되었기 때문에 기쁩니다. –

답변

-1

앱을 종료 할 때 Windows 런타임을 사용하는 Windows Phone 8.1 용 앱을 개발하면 앱이 bachground로 이동합니다. 내가 아는 한 앱을 종료 할 수 없습니다.

+0

Exit() 메서드 또는 Application.Exit() 메서드는 응용 프로그램을 종료합니다. 8.1 에뮬레이터에서 올바르게 작동합니다. 또한 Exit()를 단독으로 사용하면 전화기에서 올바르게 작동하지만 if 문 내부에 어떤 이유로 든 작동하지 않습니다. 나는 그것이 if 문이 문제 일 수 있음을 암시합니다. – smb1973

+1

이것은 단순히 잘못된 정보입니다. –

1

좋아요, 그래서 이것이 내가 생각했던 문제는 아니 었습니다.

Exit()는 괜찮 았지만 내 If 문이 올바르지 않습니다.

내가 왜 확실하지 않다

if (e.PreviousExecutionState == ApplicationExecutionState.NotRunning) 

그러나 전화

, 그것은 또한 ApplicationExecutionState.Terminated 및 ApplicationExecutionState.ClosedByUser

을 던지고 : 에뮬레이터에서 ,이 라인은 응용 프로그램의 모든 인스턴스가 폐쇄 잡는다 에뮬레이터에서 수동으로 응용 프로그램을 닫으면 여전히 ClosedByUser가 아닌 NotRunning을 반환하지만 문제가있었습니다.

도움 주셔서 감사합니다.

관련 문제