2013-07-09 70 views
2

我有一個應用程序,當我打開它一次就完全正常工作,但現在的問題是,如果用戶點擊Windows Home鍵,它退出應用程序並將我的應用程序移到背景。現在,如果用戶長按回車鍵並打開我的應用程序,它將返回到用戶點擊主鍵的同一頁面。但是,如果用戶點擊應用程序圖標,我的應用程序從一開始就開始,我不想要。請幫幫我。謝謝如何在windows phone中存儲應用程序狀態

告訴我,我應該在哪裏放置代碼,以便得到期望的結果。

我的App.xaml低於: =================

namespace MyProj 
{ 
    /// <summary> 
    /// Interaction logic for App.xaml 
    /// </summary> 
    public partial class App : Application 
    { 

     // Easy access to the root frame 
     public PhoneApplicationFrame RootFrame 
     { 
      get; 
      private set; 
     } 

     // Constructor 
     public App() 
     { 
      // Global handler for uncaught exceptions. 
      UnhandledException += Application_UnhandledException; 

      // Standard Silverlight initialization 
      InitializeComponent(); 

      // Phone-specific initialization 
      InitializePhoneApplication(); 


      // Show graphics profiling information while debugging. 
      if (System.Diagnostics.Debugger.IsAttached) 
      { 
       // Display the current frame rate counters. 
       Application.Current.Host.Settings.EnableFrameRateCounter = true; 

       // Show the areas of the app that are being redrawn in each frame. 
       //Application.Current.Host.Settings.EnableRedrawRegions = true; 

       // Enable non-production analysis visualization mode, 
       // which shows areas of a page that are handed off to GPU with a colored overlay. 
       //Application.Current.Host.Settings.EnableCacheVisualization = true; 

       // Disable the application idle detection by setting the UserIdleDetectionMode property of the 
       // application's PhoneApplicationService object to Disabled. 
       // Caution:- Use this under debug mode only. Application that disable user idle detection will continue to run 
       // and consume battery power when the user is not using the phone. 
       PhoneApplicationService.Current.UserIdleDetectionMode = IdleDetectionMode.Disabled; 
      } 

     } 

     // Code to execute when the application is launching (eg, from Start) 
     // This code will not execute when the application is reactivated 
     private void Application_Launching(object sender, LaunchingEventArgs e) 
     { 

     } 

     // Code to execute when the application is activated (brought to foreground) 
     // This code will not execute when the application is first launched 
     private void Application_Activated(object sender, ActivatedEventArgs e) 
     { 
      // Restart session 

     } 

     // Code to execute when the application is deactivated (sent to background) 
     // 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) 
     { 
      ViewModelLocator.Cleanup(); 
     } 

     // Code to execute if a navigation fails 
     private void RootFrame_NavigationFailed(object sender, NavigationFailedEventArgs e) 
     { 
      if (System.Diagnostics.Debugger.IsAttached) 
      { 
       // A navigation has failed; break into the debugger 
       System.Diagnostics.Debugger.Break(); 
      } 
     } 

     // Code to execute on Unhandled Exceptions 
     private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e) 
     { 
      if (System.Diagnostics.Debugger.IsAttached) 
      { 
       // An unhandled exception has occurred; break into the debugger 
       System.Diagnostics.Debugger.Break(); 
      } 
     } 

     #region Phone application initialization 

     // Avoid double-initialization 
     private bool phoneApplicationInitialized = false; 

     // Do not add any additional code to this method 
     private void InitializePhoneApplication() 
     { 
      if (phoneApplicationInitialized) 
       return; 

      // Create the frame but don't set it as RootVisual yet; this allows the splash 
      // screen to remain active until the application is ready to render. 
      //RootFrame = new PhoneApplicationFrame(); 
      RootFrame = new TransitionFrame(); 
      RootFrame.Navigated += CompleteInitializePhoneApplication; 

      // Handle navigation failures 
      RootFrame.NavigationFailed += RootFrame_NavigationFailed; 

      // Ensure we don't initialize again 
      phoneApplicationInitialized = true; 
     } 

     // Do not add any additional code to this method 
     private void CompleteInitializePhoneApplication(object sender, NavigationEventArgs e) 
     { 
      // Set the root visual to allow the application to render 
      if (RootVisual != RootFrame) 
       RootVisual = RootFrame; 

      // Remove this handler since it is no longer needed 
      RootFrame.Navigated -= CompleteInitializePhoneApplication; 
     } 

     #endregion 
    } 
} 
+0

@Joe Korolewicz這方面的任何幫助,真的很stucked ......對不起,我還沒有和Windows Phone的合作感謝 – Artist404

+0

所以我不能有太大的幫助,我只是重新標記它以獲得更好的可視性。 如果你想猜一猜,我會說創建另一個屬性,比如''CurrentFrame''的'RootFrame',以及每當你重新激活時,給它一個焦點。 –

+0

您可能需要閱讀IsolatedStorage以在應用程序關閉後保存內容。 –

回答

1

您需要實現墓碑的功能。剛看完
App activation and deactivation for Windows Phone

+1

我試過這個,也是TomstoneHelper.dll。但是,當我實施一切,然後啓動我的應用程序,然後按Windows home鍵,然後按appicon,我的應用程序重新啓動.. :( – Artist404

+1

「然後按appicon」,意味着點擊平鋪或長按回來按鈕,並從池中選擇應用程序?如果你使用wp7 - 當你點擊應用程序瓦片時,每個應用程序再次運行。從點擊恢復到只支持wp8 – jimpanzer

+0

的瓦片哦,那麼你能幫我解決我的問題,其實我必須保存用戶登錄會話所以當用戶以後再回來時,用戶登錄狀態會被保留下來我已經使用IsolatedstorageSettings來獲取userProfile,但是用戶登錄的響應包含一個cookie容器,用於進一步的交互,但是當我將它保存在獨立存儲中時,它不起作用。另外,cookiescontainer包含空白的cookie,它們是yim無法弄清楚什麼是來... – Artist404

相關問題