行为上报
完成登录回写后,按以下时机调用。初始化激活、登录启动上报由 SDK 自动完成。
| 时机 | 方法 |
|---|---|
| 创建角色完成 | actionReport(roleId, roleName, serverId, 1) |
| 登录角色完成 | actionReport(roleId, roleName, serverId, 2) |
| 进入角色开始游戏 | enterGame(roleId, roleName, serverId),调用一次启动心跳 |
| 离开角色 | quitGame(serverId, userId),停止心跳 |
参数说明
| 参数 | 类型 | 适用方法 | 说明 |
|---|---|---|---|
| roleId | String | actionReport、enterGame | 游戏角色 ID |
| roleName | String | actionReport、enterGame | 游戏角色名称 |
| serverId | String | 三个方法 | 游戏区服 ID,无区服时传空字符串 |
| actionType | int | actionReport | 1 创建角色、2 登录角色 |
| userId | String | quitGame | 迅雷用户 ID,取自 LoginUser.userId |
SDK 内部每 10 秒上报心跳,无需自行定时调用。
调用示例
import com.xunlei.niux.mobilegame.sdk.platform.NiuxMobileGame;
import com.xunlei.niux.mobilegame.sdk.vo.LoginUser;
// 创建角色完成时调用一次。
NiuxMobileGame.getInstance().actionReport("role_1001", "角色名称", "server_1", 1);
// 登录角色完成后,启动心跳。
NiuxMobileGame.getInstance().actionReport("role_1001", "角色名称", "server_1", 2);
NiuxMobileGame.getInstance().enterGame("role_1001", "角色名称", "server_1");
// 已进入角色后,离开时停止心跳。
LoginUser user = NiuxMobileGame.getInstance().getLoginUser();
if (user != null) {
NiuxMobileGame.getInstance().quitGame("server_1", user.userId);
}
- 切换角色:先
quitGame,再上报新角色登录并调用enterGame。 - 退出账号:先
quitGame,再onLogout,清理游戏会话。 - 收到
onExitGame:停止心跳并执行游戏退出流程。 - 当前版本切到后台不会自动停止心跳。需要暂停时,在游戏生命周期中配对调用
quitGame/enterGame。
不要在普通角色登录时重复上报创建角色,也不要重复调用同一次会话的进入/退出。