`Push.getPushKey()` 的输出总是一样的吗?
Is the output of `Push.getPushKey()` always the same?
我必须在服务器端存储 Push.getPushKey()
的输出。
总是一样吗?还是发出 REST 请求来更新其在 init()
?
中的值更好?
它的值可以是null
吗?
例如,init()
中的以下代码是一个好的方法吗?它等待非 null
PushKey,然后发送它并停止计时器。
Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
if (Push.getPushKey() != null && authToken != null) {
Rest.post(Server.getRestServerURL() + "/updatePushKey")
.jsonContent()
.header("authToken", authToken)
.body(Push.getPushKey())
.fetchAsString((Response<String> response) -> {
if (isSuccessResponse(response)) {
Log.p("PushKey successfully sent to the server", Log.INFO);
}
});
timer.cancel();
}
}
}, 1000, 1000);
感谢您的澄清。
不要使用计时器。您需要在调用 registeredForPush
回调时存储它。是的,可以更新,注册失败可以为空
我必须在服务器端存储 Push.getPushKey()
的输出。
总是一样吗?还是发出 REST 请求来更新其在 init()
?
它的值可以是null
吗?
例如,init()
中的以下代码是一个好的方法吗?它等待非 null
PushKey,然后发送它并停止计时器。
Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
if (Push.getPushKey() != null && authToken != null) {
Rest.post(Server.getRestServerURL() + "/updatePushKey")
.jsonContent()
.header("authToken", authToken)
.body(Push.getPushKey())
.fetchAsString((Response<String> response) -> {
if (isSuccessResponse(response)) {
Log.p("PushKey successfully sent to the server", Log.INFO);
}
});
timer.cancel();
}
}
}, 1000, 1000);
感谢您的澄清。
不要使用计时器。您需要在调用 registeredForPush
回调时存储它。是的,可以更新,注册失败可以为空