Fixed threading in C2DM registration that could cause an ANR on first sync:

pull/14/head
Sam Bosley 14 years ago
parent f64bfb9457
commit ae11c49c2d

@ -351,19 +351,24 @@ public class C2DMReceiver extends BroadcastReceiver {
} }
private void handleRegistration(Intent intent) { private void handleRegistration(Intent intent) {
String registration = intent.getStringExtra("registration_id"); final String registration = intent.getStringExtra("registration_id");
if (intent.getStringExtra("error") != null) { if (intent.getStringExtra("error") != null) {
Log.w("astrid-actfm", "error-c2dm: " + intent.getStringExtra("error")); Log.w("astrid-actfm", "error-c2dm: " + intent.getStringExtra("error"));
} else if (intent.getStringExtra("unregistered") != null) { } else if (intent.getStringExtra("unregistered") != null) {
// un-registration done // un-registration done
} else if (registration != null) { } else if (registration != null) {
try { DependencyInjectionService.getInstance().inject(this);
DependencyInjectionService.getInstance().inject(this); new Thread() {
actFmSyncService.invoke("user_set_c2dm", "c2dm", registration); @Override
Preferences.setString(PREF_REGISTRATION, registration); public void run() {
} catch (IOException e) { try {
Log.e("astrid-actfm", "error-c2dm-transfer", e); actFmSyncService.invoke("user_set_c2dm", "c2dm", registration);
} Preferences.setString(PREF_REGISTRATION, registration);
} catch (IOException e) {
Log.e("astrid-actfm", "error-c2dm-transfer", e);
}
}
}.start();
} }
} }
@ -372,11 +377,16 @@ public class C2DMReceiver extends BroadcastReceiver {
if(Preferences.getStringValue(PREF_REGISTRATION) != null) if(Preferences.getStringValue(PREF_REGISTRATION) != null)
return; return;
Context context = ContextManager.getContext(); new Thread() {
Intent registrationIntent = new Intent("com.google.android.c2dm.intent.REGISTER"); @Override
registrationIntent.putExtra("app", PendingIntent.getBroadcast(context, 0, new Intent(), 0)); // boilerplate public void run() {
registrationIntent.putExtra("sender", C2DM_SENDER); Context context = ContextManager.getContext();
context.startService(registrationIntent); Intent registrationIntent = new Intent("com.google.android.c2dm.intent.REGISTER");
registrationIntent.putExtra("app", PendingIntent.getBroadcast(context, 0, new Intent(), 0)); // boilerplate
registrationIntent.putExtra("sender", C2DM_SENDER);
context.startService(registrationIntent);
}
}.start();
} }
/** unregister with c2dm service */ /** unregister with c2dm service */

Loading…
Cancel
Save