Showing posts with label Windows Phone 8. Show all posts
Showing posts with label Windows Phone 8. Show all posts

Tuesday, February 19, 2013

Windows Phone 8 - Application Life Cycle

Today, I am going to explain the application life cycle of Windows Phone 8 application. Like ASP.Net Application life cycle, Windows Phone 8 (WP8) also having application life cycle. It's more or else similar to Android Application life cycle.

Application Life Cycle Flow:

Windows Phone 8 Application Life Cycle



I have explained clearly in the above flow chart on WP8 Application Life Cycle. All the application events will occur in App.xaml file.

Not Running / Idle State:
After installing or closing the application, application is in not running state.

Launching Event and Running State:
When the user open the application, application launching event occurs and application reaches to Running State. 

Deactivating Event and Dormant State:
When user receives the phone call/ opened any other application, deactivating event will occur and reaches to Dormant State. In this state, user won't lose any unsaved date (if user entered something in text box, text will be there when the application backs to running state)

Dormant State and Activating Event:
When user the finishes the phone call or close the previously opened application, application activating event will occur from dormant state. In this case, user can see the entered data.

Tombstone State and Activating Event:
When user opening the multiple application which reaches the max. limit of 6 and opening the 7th application,  1st opened application will move to tombstone state which release all the memory used by 1st application and lose unsaved data. 
When user pressing back key continuously 6 times when they are in 7th application, application activating event  of 1st application will occur and move to Running state from tombstone state.

Closing Event and Not Running State:
When user closes the application, closing event will occur and application moves to Not running state.

As a best practice, user has to save the data while application deactivating event occurs itself if they don't want to lose any data. And also, if user wants to load application wide data, it should be done in Application Launch event.

Saturday, February 16, 2013

Window Phone 8 App - Navigation

Today, I am going to explain how to do the navigation between pages and passing data between pages in Windows Phone 8 App. Before getting into application, please install following software's.

1. Visual Studio 2012
2. Windows Phone 8 SDK

Once you have installed the above software's, create the new project of Windows Phone 8 App from the project templates.

Navigation:
         To navigate from one page to another page(XAML), you have to use navigation service. See below code to navigate to Page1.xaml. If your file located in relative path, use Urikind as Relative.

     private void HyperlinkButton_Click_1(object sender, RoutedEventArgs e)  
     {  
       NavigationService.Navigate(new Uri("/Page1.xaml", UriKind.Relative));  
     }  


Go Back:

     To navigate to previous page, you have to use GoBack() method in navigation service.


     private void HyperlinkButton_Click_1(object sender, RoutedEventArgs e)  
     {  
       NavigationService.GoBack();  
     }  


Passing Data between Pages:
         To pass data between pages either you can use QueryString method or Application class. Here I am explaining QueryString method.

Source (Passing as QueryString):
      

     private void Button_Click_1(object sender, RoutedEventArgs e)  
     {  
       NavigationService.Navigate(new Uri("/Page1.xaml?name=" + txtName.Text, UriKind.Relative));  
     }  


Destination (Override the OnNavigatedTo method in PhoneApplicationPage Class):

      protected override void OnNavigatedTo(NavigationEventArgs e)  
     {  
            base.OnNavigatedTo(e);  
        string name = string.Empty;  
        if (NavigationContext.QueryString.TryGetValue("name", out name))  
          txtBox1.Text = name;  
     }  



Screenshots: