chrometophone (2)
一昨日晩なエントリを見てたら、C2DMBaseReceiver は IntentService 継承してますね。そして、onHandleIntent で主処理が書いてあります。って事は C2DMReceiver なオブジェクトを生成して startService してる箇所がどこかにあるんかな。
C2DMReceiver
定義されてるメソドが以下。
- public void onRegistrered(Context context, String registration)
- public void onUnregistered(Context context)
- public void onError(Context context, String errorId)
- public void onMessage(Context context, Intent intent)
このヒト達って IntentService 以上なレイヤの抽象メソドなのか、と思ったら C2DMBaseReceiver で定義されてる抽象メソドでした。どういった文脈で使用されているのか、を確認した方が良いかな。
C2DMBaseReceiver
とりあえず C2DMBaseReceiver#onMessage は onHandleIntent から呼び出されてます。
public final void onHandleIntent(Intent intent) {
try {
Context context = getApplicationContext();
if (intent.getAction().equals(REGISTRATION_CALLBACK_INTENT)) {
handleRegistration(context, intent);
} else if (intent.getAction().equals(C2DM_INTENT)) {
onMessage(context, intent);
} else if (intent.getAction().equals(C2DM_RETRY)) {
C2DMessaging.register(context, senderId);
}
} finally {C2DM_INTENT って何かな。
private static final String C2DM_INTENT = "com.google.android.c2dm.intent.RECEIVE";
あー、このあたりはもう少し脳がマトモな時にちゃんと再確認します。他の抽象メソドが呼ばれてるのが REGISTRATION_CALLBACK_INTENT な時に呼び出される handleRegistration 手続きからとなっている模様。
ざくっと呼び出されてるあたりのみを以下に。
String error = intent.getStringExtra(EXTRA_ERROR);
String removed = intent.getStringExtra(EXTRA_UNREGISTERED);
// 中略
if (removed != null) {
// Remember we are unregistered
C2DMessaging.clearRegistrationId(context);
onUnregistered(context);
return;
} else if (error != null) {
// we are not registered, can try again
C2DMessaging.clearRegistrationId(context);
// Registration failed
Log.e(TAG, "Registration error " + error);
onError(context, error);
// 中略
} else {
try {
onRegistrered(context, registrationId);
C2DMessaging.setRegistrationId(context, registrationId);
} catch (IOException ex) {
Log.e(TAG, "Registration error " + ex.getMessage());
}
}これはそもそも
- REGISTRATION_CALLBACK_INTENT って何か
- その場合に渡される intent なナニ
が分からんと駄目ですな。とりあえず昼間に掘る時間を確保する方向で明日以降対応します (何