Hallo zusammen,
ich hoffe ihr könnt mir weiterhelfen. Und zwar bekomme ich immre die Exception, dass ich ich meinen Service noch unregistrieren muss, allerdings habe ich keine Ahnung wo und wie.
Activity myPackage.MyMainActivity has leaked IntentReceiver com.google.android.gcm.GCMBroadcastReceiver@4243ee70 that was originally registered here. Are you missing a call to unregisterReceiver()?
In meinem Android Manifest steht:
[XML] <application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<receiver android:name=".MyBroadcastReceiver" androidermission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="myPackageName" />
</intent-filter>
</receiver>
<service android:name="myPackageName.MyIntentService" />[/XML]
MyMainActivity beinhaltet folgenden Code in der onCreate():
Mein Broadcast-Receiver:
Jedes Mal wenn MyMainActivity beendet wird, wird diese Exception geworden, allerdings weiß ich nicht wie und wo ich den Service unregistrieren kann.
Vielen Dank und viele Grüße.
ich hoffe ihr könnt mir weiterhelfen. Und zwar bekomme ich immre die Exception, dass ich ich meinen Service noch unregistrieren muss, allerdings habe ich keine Ahnung wo und wie.
Activity myPackage.MyMainActivity has leaked IntentReceiver com.google.android.gcm.GCMBroadcastReceiver@4243ee70 that was originally registered here. Are you missing a call to unregisterReceiver()?
In meinem Android Manifest steht:
[XML] <application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<receiver android:name=".MyBroadcastReceiver" androidermission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="myPackageName" />
</intent-filter>
</receiver>
<service android:name="myPackageName.MyIntentService" />[/XML]
MyMainActivity beinhaltet folgenden Code in der onCreate():
Java:
GCMRegistrar.checkDevice(this);
GCMRegistrar.checkManifest(this);
final String regId = GCMRegistrar.getRegistrationId(this);
if (regId.equals("")) {
GCMRegistrar.register(this, "MEINKEY");
} else {
Log.v(TAG, "Already registered");
}
Mein Broadcast-Receiver:
Java:
public class MyBroadcastReceiverextends BroadcastReceiver {
@Override
public final void onReceive(Context context, Intent intent) {
MyIntentService.runIntentInService(context, intent);
setResult(Activity.RESULT_OK, null, null);
}
}
Java:
public class MyIntentService extends IntentService {
public MyIntentService () {
super("MyIntentService");
}
private static PowerManager.WakeLock sWakeLock;
private static final Object LOCK = MyIntentService.class;
private static final String TAG = "MyIntentService";
static void runIntentInService(Context context, Intent intent) {
synchronized(LOCK) {
if (sWakeLock == null) {
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
sWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "my_wakelock");
}
}
sWakeLock.acquire();
intent.setClassName(context, MyIntentService.class.getName());
context.startService(intent);
}
@Override
public final void onHandleIntent(Intent intent) {
try {
String action = intent.getAction();
if (action.equals("com.google.android.c2dm.intent.REGISTRATION")) {
handleRegistration(intent);
} else if (action.equals("com.google.android.c2dm.intent.RECEIVE")) {
handleMessage(intent);
}
} finally {
synchronized(LOCK) {
sWakeLock.release();
}
}
}
private void handleRegistration(Intent intent) {
String registrationId = intent.getStringExtra("registration_id");
String error = intent.getStringExtra("error");
String unregistered = intent.getStringExtra("unregistered");
// registration succeeded
if (registrationId != null) {
//Mache etwas mit den Daten
}
// unregistration succeeded
if (unregistered != null) {
// get old registration ID from shared preferences
// notify 3rd-party server about the unregistered ID
}
// last operation (registration or unregistration) returned an error;
if (error != null) {
// Registration failed, should try again later.
Log.d("c2dm", "registration failed");
if(error == "SERVICE_NOT_AVAILABLE"){
Log.d("c2dm", "SERVICE_NOT_AVAILABLE");
}else if(error == "ACCOUNT_MISSING"){
Log.d("c2dm", "ACCOUNT_MISSING");
}else if(error == "AUTHENTICATION_FAILED"){
Log.d("c2dm", "AUTHENTICATION_FAILED");
}else if(error == "TOO_MANY_REGISTRATIONS"){
Log.d("c2dm", "TOO_MANY_REGISTRATIONS");
}else if(error == "INVALID_SENDER"){
Log.d("c2dm", "INVALID_SENDER");
}else if(error == "PHONE_REGISTRATION_ERROR"){
Log.d("c2dm", "PHONE_REGISTRATION_ERROR");
}
}
}
private void handleMessage(Intent intent) {
// generates a system notification to display the Text
}
}
Jedes Mal wenn MyMainActivity beendet wird, wird diese Exception geworden, allerdings weiß ich nicht wie und wo ich den Service unregistrieren kann.
Vielen Dank und viele Grüße.