다음을 통해 공유


앱 다시 시작 방법(DirectX 및 C++)

이 토픽에서는 시스템에서 UWP(Universal Windows Platform) DirectX 앱을 재개할 때 중요한 애플리케이션 데이터의 복원 방법을 보여 줍니다.

Resuming(다시 시작) 이벤트 처리기 등록

CoreApplication::Resuming 이벤트를 처리할 수 있도록 등록하세요. 이렇게 하면 사용자가 앱에서 전환했다가 다시 해당 앱으로 전환했다는 것이 표시됩니다.

이 코드를 뷰 공급자의 IFrameworkView::Initialize 메서드 구현에 추가합니다.

// The first method is called when the IFrameworkView is being created.
void App::Initialize(CoreApplicationView^ applicationView)
{
  //...
  
    CoreApplication::Resuming +=
        ref new EventHandler<Platform::Object^>(this, &App::OnResuming);
    
  //...

}

일시 중단 후 표시된 콘텐츠 새로 고침

앱이 다시 시작 이벤트를 처리하면 표시된 콘텐츠를 새로 고칠 수 있습니다. CoreApplication::Suspending에 대한 처리기를 사용하여 저장한 앱을 복원하고 처리를 다시 시작합니다. 게임 개발: 오디오 엔진을 일시 중단한 경우 이제 다시 시작할 시간입니다.

void App::OnResuming(Platform::Object^ sender, Platform::Object^ args)
{
    // Restore any data or state that was unloaded on suspend. By default, data
    // and state are persisted when resuming from suspend. Note that this event
    // does not occur if the app was previously terminated.

    // Insert your code here.
}

이 콜백은 앱의 CoreWindow에 대해 CoreDispatcher에서 처리하는 이벤트 메시지로 발생합니다. 앱의 기본 루프(보기 공급자의 IFrameworkView::Run 메서드에서 구현됨)에서 CoreDispatcher::ProcessEvents를 호출하지 않으면 이 콜백이 호출되지 않습니다.

// This method is called after the window becomes active.
void App::Run()
{
    while (!m_windowClosed)
    {
        if (m_windowVisible)
        {
            CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessAllIfPresent);

            m_main->Update();

            if (m_main->Render())
            {
                m_deviceResources->Present();
            }
        }
        else
        {
            CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessOneAndAllPending);
        }
    }
}

설명

사용자가 다른 앱 또는 데스크톱으로 전환할 때마다 시스템이 앱을 일시 중단합니다. 사용자가 이 앱으로 다시 전환할 때마다 시스템이 해당 앱을 다시 시작합니다. 시스템이 앱을 다시 시작할 경우, 변수 및 데이터 구조의 콘텐츠는 시스템이 앱을 일시 중단하기 전과 동일합니다. 시스템은 앱을 중단된 위치에서 정확하게 복원합니다. 따라서 해당 앱은 백그라운드에서 실행 중인 것처럼 사용자에게 표시됩니다. 그러나 앱이 상당한 시간 동안 일시 중단되었을 수 있으므로 앱이 일시 중단된 동안 변경되었을 수 있는 표시된 콘텐츠를 새로 고치고 렌더링 또는 오디오 처리 스레드를 다시 시작해야 합니다. 이전 일시 중단 이벤트 중에 게임 상태 데이터를 저장한 경우 지금 복원합니다.