본문 바로가기

WindowsRT

WinRT앱은 어떻게 시작이 되는가?!

개발을 시작하기에 앞서 우선 앱이 어떻게 시작이 되는지를 알아 보는 것이 도움이 될 것이라고 생각이 된다. 앱의 시작은 App 에서 시작하게 된다.

응? 그냥 App 에서 무조건? 그냥 알아서? 라고 외워도 되겠지만 쵸큼만 더 알아 보도록 하자

Debug모드로 compile을 하면 bin폴더 아래에 Debug 폴더가 생기는데 거기에는 AppxManifest.xml 이 있다. 이걸 열어 보도록 하자.

<?xml version="1.0" encoding="utf-8"?>

<Package xmlns="http://schemas.microsoft.com/appx/2010/manifest" xmlns:build="http://schemas.microsoft.com/developer/appx/2012/build" IgnorableNamespaces="build">

  <!--

    THIS PACKAGE MANIFEST FILE IS GENERATED BY THE BUILD PROCESS.

 

    Changes to this file will be lost when it is regenerated. To correct errors in this file, edit the source .appxmanifest file.

 

    For more information on package manifest files, see http://go.microsoft.com/fwlink/?LinkID=241727

  -->

  <Identity Name="864d155f-f318-4c6d-ab9b-bd10293ee206" Publisher="CN=howard" Version="1.0.0.0" ProcessorArchitecture="neutral" />

  <Properties>

    <DisplayName>GridAppTest</DisplayName>

    <PublisherDisplayName>howard</PublisherDisplayName>

    <Logo>Assets\StoreLogo.png</Logo>

  </Properties>

  <Prerequisites>

    <OSMinVersion>6.2.1</OSMinVersion>

    <OSMaxVersionTested>6.2.1</OSMaxVersionTested>

  </Prerequisites>

  <Resources>

    <Resource Language="EN-US" />

  </Resources>

  <Applications>

    <Application Id="App" Executable="GridAppTest.exe" EntryPoint="GridAppTest.App3">

      <VisualElements DisplayName="GridAppTest" Logo="Assets\Logo.png" SmallLogo="Assets\SmallLogo.png" Description="GridAppTest" ForegroundText="light" BackgroundColor="#464646">

        <DefaultTile ShowName="allLogos" />

        <SplashScreen Image="Assets\SplashScreen.png" />

      </VisualElements>

    </Application>

  </Applications>

  <Capabilities>

    <Capability Name="internetClient" />

  </Capabilities>

  <build:Metadata>

    <build:Item Name="TargetFrameworkMoniker" Value=".NETCore,Version=v4.5" />

    <build:Item Name="VisualStudio" Version="11.0" />

    <build:Item Name="OperatingSystem" Version="6.2.9200.16384 (win8_rtm.120725-1247)" />

    <build:Item Name="Microsoft.Build.AppxPackage.dll" Version="11.0.50727.1" />

    <build:Item Name="Microsoft.Windows.UI.Xaml.Build.Tasks.dll" Version="11.0.50727.1" />

    <build:Item Name="MakePri.exe" Version="6.2.9200.16384 (win8_rtm.120725-1247)" />

  </build:Metadata>

</Package>

앱의 다양한 정보가 있는데 이중에서 Applications 아래에 Application의 속성 중에 EntryPoint로 “프로젝트명.App” 이 설정 되어 있는 것을 확인 할 수 있다.!! 그렇다!!! AppxManifest 파일에 App의 Entry Point을 설정해주었기에 App이 처음에 불리게 되는 것이다!! 

아무튼 App이 앱의 시작점이라는 것을 알았으니 거기서부터 시작해 보도록 하겠다.

구현 부분을 제거하고 나면 다음과 같은 모습이다.

sealed partial class App : Application

{

    public App()

    protected override async void OnLaunched(LaunchActivatedEventArgs args)

    private async void OnSuspending(object sender, SuspendingEventArgs e)
}

우선 생성자가 존재하고 OnLaunched라는 이벤트 핸들러를 override해주고 있으며, OnSuspending 이벤트 핸들러가 존재한다.

여기서 OnLaunched을 좀 더 자세히 보도록 하겠다.

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();

    //Associate the frame with a SuspensionManager key                               

    SuspensionManager.RegisterFrame(rootFrame, "AppFrame");

 

    if (args.PreviousExecutionState == ApplicationExecutionState.Terminated)

    {

        // Restore the saved session state only when appropriate

        try

        {

            await SuspensionManager.RestoreAsync();

        }

        catch (SuspensionManagerException)

        {

            //Something went wrong restoring state.

            //Assume there is no state and continue

        }

    }

 

    // Place the frame in the current Window

    Window.Current.Content = rootFrame;

}

if (rootFrame.Content == null)

{

    // 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(GroupedItemsPage), "AllGroups"))

    {

        throw new Exception("Failed to create initial page");

    }

}

// Ensure the current window is active

Window.Current.Activate();

찬찬히 보면 사실 별거 없다! 간추려 설명하자면 현재 앱의 Content에 Frame이 없는 경우 하나 만들어서 넣어주고, 넣어 줄 때 다시 Frame의 Content가 비워 있다면 여기서는 GroupedItemsPage로 Navigation을 시도하게 된다.

즉!! 앱이 처음 시작되어 원하는 페이지로 이동을 하려면 GroupedItemsPage부분을 원하는 페이지로 변경하면 된다!! 그리고 나서는 우리가 보는 앱의 모습이 화면에 나오게 된다.

참으로 쉽다!! 별거 없다! 자 이제 개발 궈궈 무브무브