Android 5.0 Cannot start a service in its own process, service has to be an explicit service

  • Hello,

    I have a android service for a chatter app.
    This service runs in its own process and manage the connection to the server with push Technology.

    Manifest.xml:

    But if i want to start the service in the MainActivity, it causes an exception.

    MainActivity.java:

    ServiceConnectionManager.java:

    IChatService is the AIDL interface.

    ChatService.java:

    I get the following error message:

    The method createExplicitFromImplicitIntent(Context context, Intent implicitIntent) is from stackoverflow, but it doesnt work.
    The service has to be a explecit service since Android 5.0, because they had change something in the code.
    Now i have tried this, but it doesnt work.
    Can anyone help me?

    Do i have to change the Mainfest.xml, so that the service is founded by the PackageManager?

  • I dunno where u wanna c 'service has to be explicit'.

    I onyl c 'Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.content.Intent.resolveTypeIfNeeded(android.content.ContentResolver)' on a null object reference'

    Je mehr Käse, desto mehr Löcher.
    Je mehr Löcher, desto weniger Käse.
    Daraus folgt: je mehr Käse, desto weniger Käse.

    »Dies ist ein Forum. Schreibt Eure Fragen in das Forum, nicht per PN!«

  • Vielen Dank! :D

    Ich habe soeben bemerkt, dass dies ja ein deutsches Forum ist. :D
    Die explicit Fehlermeldung kommt nicht mehr, seit ich diese createExplicitIntent Methode von StackOverFlow eingebaut habe.
    Aber wieso bekommt die Methode eine NullPointerException?

  • Für mich liest es sich so, als wäre Dein pm in Zeile 61 ServiceConnectionManager.java schlicht null.

    Je mehr Käse, desto mehr Löcher.
    Je mehr Löcher, desto weniger Käse.
    Daraus folgt: je mehr Käse, desto weniger Käse.

    »Dies ist ein Forum. Schreibt Eure Fragen in das Forum, nicht per PN!«

  • Das könnte daran liegen, dass die Variable intent bereits ein explicit service ist, nachdem bereits folgende Methode aufgerufen wurde:

    Java
    intent = ServiceConnectionManager.createExplicitFromImplicitIntent(ctx.getApplicationContext(), intent)
  • Leider funktioniert der Service immer noch nicht.
    Weiß jemand, wieso die NullPointerException geworfen wird oder was vllt. in der Manifest geändert werden muss?

  • Code
    java.lang.RuntimeException: Unable to start activity ComponentInfo{
    com.jukusoft.chatter/com.jukusoft.chatter.MainActivity}:
    java.lang.NullPointerException: Attempt to invoke virtual method
    'java.lang.String android.content.Intent.resolveTypeIfNeeded(android.content.ContentResolver)'
    on a null object reference

    Er spricht hier die MainActivity an, die ihm Probleme bereitet.

    Java
    this.serviceConnectionManager = new ServiceConnectionManager();
        	if (!this.serviceConnectionManager.isServiceAvailable()) {
            	//start service
            	this.serviceConnectionManager.startService(this.getBaseContext());
        	}

    Könnte ja an dem liegen, was du hier reinhaust. Zeig mal die ganze MainActivity bzw. kommentiere mal ne Zeile aus, teste es neu, kommentiere wieder etwas aus, teste wieder usw.

    :Android:

  • Das habe ich bereits gemacht.
    Es liegt nur an der Methode startService().

    MainActivity.java:

    Einmal editiert, zuletzt von JuKu (20. Januar 2015 um 14:52)

  • Android kann den Service anscheinend derzeit nicht binden.

    ServiceConnectionManager.java:

    Hier noch die ADB Logs:

  • Ich habe das Probem soeben gelöst.
    Ich benötige keinen explicit service dafür.

    Quelle: http://developer.android.com/guide/componen…ts-filters.html

    ServiceConnectionManager.java:

Jetzt mitmachen!

Sie haben noch kein Benutzerkonto auf unserer Seite? Registrieren Sie sich kostenlos und nehmen Sie an unserer Community teil!