11

I am implementing an aidl interface, and for some reason, the following code gives me an error:

// IApkinsonCallback.aidl
package com.applications.philipp.apkinson.interfaces;

/** Interface implemented by Apkinson so plugins can give feedback */
oneway interface IApkinsonCallback {
    /** To be called by plugin after registration to setup data for result viewing
        Usage of this data:
        Intent intent = new Intent(intentActionName);
        intent.putExtra(bundleResultKey, result);
        startActivity(intent);
     */
    void onRegistered(String intentActionName, String bundleResultKey);
    /** To be called by plugin when result is ready after stopData() was called by Apkinson */
    void onResult(String result);
    /** Called if an error occured in the plugin and the call won't be successfully handled */
    void onError(String errorMsg);
}

ERROR:

<interface declaration>, <parcelable declaration>, AidlTokenType.import or AidlTokenType.package expected, got 'oneway'

When I remove the oneway keyword, everything works fine. But this cannot be the solution for my problem...

PKlumpp
  • 4,913
  • 8
  • 36
  • 64

2 Answers2

15

Summary:

Move the oneway keyword to the method level.

Explanation-
This is very weird problem that related to the /platform/frameworks/base/api/current.txt file inside the Android framework (Big txt file that contains every function and being used by Android Studio) .

Example-

/** Interface implemented by Apkinson so plugins can give feedback */
interface IApkinsonCallback {
    /** To be called by plugin after registration to setup data for result viewing
        Usage of this data:
        Intent intent = new Intent(intentActionName);
        intent.putExtra(bundleResultKey, result);
        startActivity(intent);
     */
    oneway void onRegistered(String intentActionName, String bundleResultKey);
    /** To be called by plugin when result is ready after stopData() was called by Apkinson */
    oneway void onResult(String result);
    /** Called if an error occured in the plugin and the call won't be successfully handled */
    oneway void onError(String errorMsg);
}

You will get the same result but without the error.

Nir Duan
  • 6,164
  • 4
  • 24
  • 38
0

I test on AndroidStudio 4.1 and I see that

oneway interface IApkinsonCallback {
      void valueChange();
}
// AndroidStudio dislay error: <interface declaration>, <parcelable declaration>, AidlTokenType.import or AidlTokenType.package expected, got 'oneway'
// BUT it compiles ok and work ok
// AND ALL METHOD INSIDE INTERFACE is oneway method

.

interface IApkinsonCallback {

     oneway void valueChange(); // WORK AS EXPECTED, asynchronous remote call
     
     int getData(); // WORK AS EXPECTED, synchronous remote call

     oneway int getData(); // COMPILE ERROR: oneway method 'getData' cannot return a value
}
Linh
  • 57,942
  • 23
  • 262
  • 279