user842225
user842225

Reputation: 6009

AIDL method is not generated

I need to pass an Intent object to remote service through AIDL, I tried:

In aidl file:

import android.content.Intent;
parcelable Intent

void passIntent(Intent intent);

In my remote serivce class:

private final IMyService.Stub mBinder = new IMyService.Stub() {
  //ERROR: The method must override or implement a supertype method
  @Override
  public void passIntent(Intent intent) {

  }
}

I got compilation error The method must override or implement a supertype method.

Then I checked gen/ folder, IMyService.java, the method is not generated. Project clean & re-build doesn't help.

Why? Does Android not allow to pass Intent object in this way? If so, how can I pass Intent object from Activity to service in another process?

Upvotes: 2

Views: 2084

Answers (1)

CommonsWare
CommonsWare

Reputation: 1007369

When I created a new Android Studio project and defined this AIDL based on your question:

package com.commonsware.myapplication;

import android.content.Intent;

interface IMyService {
    void passIntent(Intent intent);
}

I received a build error:

.../IMyService.aidl:6 parameter 1: 'Intent intent' can be an out parameter, so you must declare it as in, out or inout.

Changing the AIDL to:

package com.commonsware.myapplication;

import android.content.Intent;

interface IMyService {
    void passIntent(in Intent intent);
}

resulted in IMyService.java being generated with the proper method.

So, add the in keyword to your passIntent() declaration, and try that.

Upvotes: 1

Related Questions