在Sony SmartWatch2的控制扩展中,我可以通过onKey接收返回键,但是如何防止扩展终止?我想挂钩后退键来做一些过程,但按后退键会终止扩展。
在 SampleAdvancedControlExtension 中,它似乎通过启动新控件来阻止后退按钮,但我只使用单个控件。
public void onKey(int action, int keyCode, long timeStamp) {
Log.v(SampleExtensionService.LOG_TAG, "onKey");
if (action == Control.Intents.KEY_ACTION_RELEASE
&& keyCode == Control.KeyCodes.KEYCODE_BACK) {
Log.d(SampleExtensionService.LOG_TAG, "onKey() - back button intercepted.");
onBack();
} else if (mCurrentControl != null) {
super.onKey(action, keyCode, timeStamp);
}
}
/**
* Closes the currently open control extension. If there is a control on the
* back stack it is opened, otherwise extension is closed.
*/
public void onBack() {
Log.v(SampleExtensionService.LOG_TAG, "onBack");
if (!mControlStack.isEmpty()) {
Intent backControl = mControlStack.pop();
ControlExtension newControl = createControl(backControl);
startControl(newControl);
} else {
stopRequest();
}
}
好的,我发现了问题所在。我必须在 RegistrationInformation 类中添加以下方法。
@Override
public boolean controlInterceptsBackButton() {
// Extension has it's own navigation, handles back presses.
return true;
}