[英]GCM GcmListenerService and 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));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.