You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

wipe data后deviceToken与pushType为空,重启恢复的问题求助

问题分析:仅重启设备后DeviceToken与PushType才正常,Wipe Data后为空的原因

在用户注册场景中,只有重启设备后,deviceToken和pushType才能正常设置;仅执行Wipe Data操作的话,这两个字段会为空,但其他参数均与之前设置一致且正确。以下是可能的原因:

  • FCM Token生成时机延迟:Wipe Data后,Firebase服务未立即触发Token生成流程。Parse依赖FCM返回的Token填充deviceToken,重启设备会触发系统级FCM初始化,强制请求Token;而单纯清数据后,App启动时FCM服务可能还未完成初始化,导致Parse提前保存Installation时未获取到Token。
  • Parse Installation初始化顺序错误:代码中直接获取ParseInstallation.getCurrentInstallation()并保存,但此时FCM可能还未完成Token的获取与绑定。重启设备后,系统提前完成FCM初始化,App启动时Parse能直接拿到已生成的Token。
  • 服务启动优先级问题:ParseFirebaseMessagingService的启动时机滞后,Wipe Data后App首次启动时该服务未被触发,无法接收FCM的Token回调,导致deviceToken为空。重启设备后系统会重新调度服务,确保其正常启动并处理Token回调。
  • Parse本地缓存异常:Wipe Data操作可能未完全清除Parse的本地缓存,导致Installation对象处于异常状态;重启设备会彻底重置系统服务与缓存,让Parse重新初始化并正确绑定FCM Token。

相关代码

Java 实现代码

ParseInstallation installation = ParseInstallation.getCurrentInstallation();
channels.add("News");
installation.put("GCMSenderId", getString(R.string.firebase_sender_id));
installation.put("channels", channels);
installation.saveInBackground(new SaveCallback() {
    @Override
    public void done(ParseException e) {
        Log.i("Parse", "Installation have sent successfully!");
    }
});
ParseUser user = ParseUser.getCurrentUser();

AndroidManifest 配置

<receiver
    android:name="com.parse.ParsePushBroadcastReceiver"
    android:exported="false">
    <intent-filter>
        <action android:name="com.parse.push.intent.RECEIVE" />
        <action android:name="com.parse.push.intent.OPEN" />
        <action android:name="com.parse.push.intent.DELETE" />
    </intent-filter>
</receiver>
<service
    android:name="com.parse.fcm.ParseFirebaseMessagingService"
    android:exported="false">
    <intent-filter>
        <action android:name="com.google.firebase.MESSAGING_EVENT" />
    </intent-filter>
</service>

内容的提问来源于stack exchange,提问作者breakcore pashok

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.12 19:53:11