GCM IntentService Problem

Megaman2012

Mitglied
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" android:permission="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.
 

mjdv

Bekanntes Mitglied
Naja zum Beispiel in onPause, onStop oder auch onDestroy. Aber unregisterReceiver klingt eher nach einem BroadcastReceiver und nicht nach einem Service
 

Megaman2012

Mitglied
Danke schön für die Antwort.

Allerdings habe ich den Broadcast Receiver im Manifest deklariert. Und deswegen weiß ich nicht wie ich im Code darauf zugreifen kann.
Muss ich ihn überhaupt unregistrieren? Ich meine dann werden ja keine Nachrichten mehr empfangen oder?
 

mjdv

Bekanntes Mitglied
Naja wenn du irgendwann keine Nachrichten mehr empfangen möchtest dann solltest du ihn auch unregistern. Aber ich glaube wenn du den BroadcastReceiver im Manifest registrierst dann ist der immer aktiv so lange die App installiert ist.
 
Ähnliche Java Themen
  Titel Forum Antworten Datum
W IntentService Alarm Manager Android & Cross-Platform Mobile Apps 0
W Android IntentService / Broadcast / Taskkiller (LBE Privacy Guard) Android & Cross-Platform Mobile Apps 0
W Prüfen, ob App auf Gerät installiert ist Problem S10 Android & Cross-Platform Mobile Apps 11
W In App Purchase Problem? Android & Cross-Platform Mobile Apps 36
W Problem mit Android Studio Android & Cross-Platform Mobile Apps 0
T Android R.string.test+i Problem Android & Cross-Platform Mobile Apps 2
K Android to Pi | Websocket Problem Android & Cross-Platform Mobile Apps 3
N Intent und finish() Problem Android & Cross-Platform Mobile Apps 5
B Android App Programmierung Einsteiger Problem Android & Cross-Platform Mobile Apps 4
emeraldo Android Problem mit Bottomnavmenu Android & Cross-Platform Mobile Apps 10
I Das Problem mit der Tastatur... android:windowSoftInputMode="adjustPan" Android & Cross-Platform Mobile Apps 1
M Android App → Problem mit dem Speichern von einem Bitmap–Objekt. Android & Cross-Platform Mobile Apps 1
A Android Android Studio Emulator Problem Android & Cross-Platform Mobile Apps 1
S Android Studio Bluetooth App Problem Android & Cross-Platform Mobile Apps 6
J TicTacToe Problem bei kontrolle Android & Cross-Platform Mobile Apps 7
J Button array ID Problem Android & Cross-Platform Mobile Apps 2
M Problem bei Werteübergabe, MSQL verbindung Android & Cross-Platform Mobile Apps 3
S Android Problem mit Android Virtual Device erstellung. Android & Cross-Platform Mobile Apps 2
Anfänger2011 Text to Speech Problem Android & Cross-Platform Mobile Apps 1
S Android Android java onclick listener Problem Android & Cross-Platform Mobile Apps 9
A Android Problem mit ListView und OnItemClickListener.. Android & Cross-Platform Mobile Apps 10
K Problem mit arraylist und button Android & Cross-Platform Mobile Apps 16
R W-Lan Problem über Sockets Android & Cross-Platform Mobile Apps 1
P ViewPager Problem Android & Cross-Platform Mobile Apps 1
A Android Problem mit Video von Youtube abspielen Android & Cross-Platform Mobile Apps 4
A Android Problem mit Zurücktaste und ausgabe der Aktuellen Seite Android & Cross-Platform Mobile Apps 6
B Android Problem mit Soundwiedergabe Android & Cross-Platform Mobile Apps 2
T Android Android Sensor: Java Problem Android & Cross-Platform Mobile Apps 1
G Problem beim Rendern von 3D-Objekt Android & Cross-Platform Mobile Apps 0
L Android Gyroscope Sensor Problem Android & Cross-Platform Mobile Apps 2
S Android GPS Problem Android & Cross-Platform Mobile Apps 24
J Eclipse Emulator Problem Android & Cross-Platform Mobile Apps 1
J Eclipse Emulator Problem Android & Cross-Platform Mobile Apps 0
B Android Problem mit Rückgabewert Android & Cross-Platform Mobile Apps 13
L Android komisches Bitmap-Größe-Problem Android & Cross-Platform Mobile Apps 8
D Android Layout Problem Android & Cross-Platform Mobile Apps 2
R Problem mit View in ScrollView Android & Cross-Platform Mobile Apps 6
R Eclipse + AndroidSDK - Problem mit Referenzen Android & Cross-Platform Mobile Apps 6
M Problem mit setOnClickListener Android & Cross-Platform Mobile Apps 4
DaniSahne96 Problem beim Appdebuggen auf Smartphone Android & Cross-Platform Mobile Apps 3
P Android Problem beim Widget - Denkfehler ? Android & Cross-Platform Mobile Apps 2
D Android Gallery Problem Android & Cross-Platform Mobile Apps 5
P Problem mit Cell id Android & Cross-Platform Mobile Apps 6
L Android Problem mit "spinner" Android & Cross-Platform Mobile Apps 10
D Android problem mit geschwindigkeitsberechnung app Android & Cross-Platform Mobile Apps 2
E Android Problem mit Contact Provider Android & Cross-Platform Mobile Apps 1
H Android Problem mit ListActivity Android & Cross-Platform Mobile Apps 3
S Android Layout Problem mit fill_parent Android & Cross-Platform Mobile Apps 5
F Android ExpandableList, SimpleCursorTreeAdapter, Cursor Problem Android & Cross-Platform Mobile Apps 2
A Android Problem mit Long.getLong() bzw. Integer.getInteger() Android & Cross-Platform Mobile Apps 2
A Problem mit HTTP- Verbindung Android & Cross-Platform Mobile Apps 4
V [Java] und [JavaME] ClientServer StreamConnection . Problem beim lesen / schreiben Android & Cross-Platform Mobile Apps 2
F Eclipse JAD File erzeugen -- Problem Android & Cross-Platform Mobile Apps 10
R Ein Problem beim ausführen von folgendem Quelltext Android & Cross-Platform Mobile Apps 11
M Problem mit dem Auslesen von System Properties Android & Cross-Platform Mobile Apps 7
P wtk problem Android & Cross-Platform Mobile Apps 3
G Math exp() Problem Android & Cross-Platform Mobile Apps 4
G S40 Problem Android & Cross-Platform Mobile Apps 8
A Problem beim Subtrahieren eines Double von einem Double Android & Cross-Platform Mobile Apps 5
C Problem Device/Emulator wird nicht erkannt Android & Cross-Platform Mobile Apps 3
S Image Problem Android & Cross-Platform Mobile Apps 11
M Problem mit den Softkeys Android & Cross-Platform Mobile Apps 4
G J2ME jar-problem Android & Cross-Platform Mobile Apps 10
S Komisches Problem Android & Cross-Platform Mobile Apps 3
F Problem beim Erstellen der Jar File Android & Cross-Platform Mobile Apps 4
A Problem: Canvas-Grösse Motorola RAZR v3r Android & Cross-Platform Mobile Apps 8
S Problem mit Einbindung einer externer Bibliothek Android & Cross-Platform Mobile Apps 2
G Random - Problem Android & Cross-Platform Mobile Apps 5
E problem mit den resourcen Android & Cross-Platform Mobile Apps 2
O Problem mit Datagramconnection Android & Cross-Platform Mobile Apps 2
P Problem mit der Uhrzeit Android & Cross-Platform Mobile Apps 2
S Problem auf dem Handy Android & Cross-Platform Mobile Apps 3

Ähnliche Java Themen

Neue Themen


Oben