> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Game Saves 作用中裝置變更

> 處理 PlayFab Game Saves 作用中裝置變更，以防止玩家在多個平台之間於工作階段中途切換裝置時遺失進度。

## 處理作用中裝置變更

當玩家在工作階段中途切換裝置時，請務必防止他們因同時在多部裝置上遊玩而意外遺失進度。

### 問題案例

1. **玩家從裝置 A 開始**：開始遊玩，裝置 A 成為「作用中」裝置
2. **玩家切換至裝置 B**：登入並選擇「同步上次儲存的資料」
3. **裝置 B 成為作用中**：裝置 A 不再是作用中裝置，但可能並不知道這一點
4. **遺失進度的風險**：玩家可能會繼續在裝置 A 上遊玩，造成衝突的存檔狀態

### 解決方案：作用中裝置回呼

接聽作用中裝置變更，並正常處理轉換：

```cpp theme={null}
// Set up the active device changed callback during initialization
hr = PFGameSaveFilesSetActiveDeviceChangedCallback(
    optionalTaskQueue,                    // Use nullptr for immediate callback
    MyActiveDeviceChangedCallback,        // Your callback function
    contextPtr);                          // Optional context for your callback
```

### 回呼實作範例

```cpp theme={null}
void MyActiveDeviceChangedCallback(void* context)
{
    // The current device is no longer active for Game Saves
    
    // 1. Pause the game immediately
    
    // 2. Inform the player what happened
    // with a message such as:
    // "Your game progress is being continued on another device."
    // "Returning to main menu to prevent data loss."
    
    // 3. Return to a safe state (main menu)
    
    // 4. Re-initialize Game Saves system when ready to play again
    // (The player will need to sync again from the main menu)
}
```

### XBOX 特定例外

如果您的遊戲只使用 XBOX 的**單一存在點 (SPOP)** 功能登入，則會自動防止此案例。SPOP 可確保使用者一次只能在一部 XBOX 裝置上登入。

### 最佳做法

* 對於多平台遊戲，**一律實作此回呼**
* 回呼觸發時**立即暫停遊戲**
* **清楚地向玩家說明**為什麼他們會被帶回功能表
* 透過返回主功能表而非關閉遊戲，**讓重新進入更容易**


## Related topics

- [Game Saves 快速入門](/zh-TW/services/playfab/player-progression/game-saves/quickstart.md)
- [Game Saves UI 回呼](/zh-TW/services/playfab/player-progression/game-saves/ui-callbacks.md)
- [Game Saves 錯誤處理常見問題集](/zh-TW/services/playfab/player-progression/game-saves/error-handling-faq.md)
- [PFGameSaveFilesSetActiveDeviceChangedCallback](/zh-TW/services/playfab/api-references/c/pfgamesavefiles/functions/pfgamesavefilessetactivedevicechangedcallback.md)
- [PFGameSaveFilesActiveDeviceChangedCallback](/zh-TW/services/playfab/api-references/c/pfgamesavefiles/functions/pfgamesavefilesactivedevicechangedcallback.md)
