簡體   English   中英

GCM:我應該在Android中自己啟動InstanceIDListenerService嗎?

[英]GCM: Should I start InstanceIDListenerService by myself in Android?

我從官方網站上下載了GCM的示例,有一個可以檢測刷新令牌的服務,代碼如下:

public class MyInstanceIDListenerService extends InstanceIDListenerService {

private static final String TAG = "MyInstanceIDLS";

/**
 * Called if InstanceID token is updated. This may occur if the security of
 * the previous token had been compromised. This call is initiated by the
 * InstanceID provider.
 */
// [START refresh_token]
@Override
public void onTokenRefresh() {
    // Fetch updated Instance ID token and notify our app's server of any changes (if applicable).
    Intent intent = new Intent(this, RegistrationIntentService.class);
    startService(intent);
}
// [END refresh_token]
}

我的問題是:我應該自己編寫代碼來啟動服務嗎? 就像:

startService(new Intent(getActivity(), MyInstanceIDListenerService.class));

否。必要時,Google Play服務會啟動此服務。 只要確保在您的AndroidManifest.xml文件中定義服務即可。 另外,如果您只是剛入門,則可能需要看看更容易實現的FCM

請在此處查看FCM示例。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM