我正在实现一个aidl接口,由于某种原因,以下代码给出了一个错误:
// 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);
}
错误:
<interface declaration>, <parcelable declaration>, AidlTokenType.import or AidlTokenType.package expected, got 'oneway'
当我删除oneway
关键字时,一切正常。但这不能解决我的问题......
答案 0 :(得分:8)
将oneway
关键字移至方法级别。
<强>解释 - 强>
这是与Android框架内的/platform/frameworks/base/api/current.txt
文件相关的非常奇怪的问题(包含所有功能并由Android Studio使用的Big txt文件)。
示例 -
/** 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);
}
您将获得相同的结果但没有错误。
答案 1 :(得分:0)
我在 AndroidStudio 4.1 上测试,我看到了
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
}