问题描述
在控制扩展索尼SmartWatch2,我可以通过onKey收到返回键,但我怎么能prevent扩展的终止?我想钩返回键做一些处理,但是pressing返回键终止扩展。
在SampleAdvancedControlExtension,现在看来似乎是阻止后退按钮通过启动新的控制,但我只使用单一的控制。
公共无效onKey(INT行动,诠释键code,长时间戳){
Log.v(SampleExtensionService.LOG_TAGonKey);
如果(行动== Control.Intents.KEY_ACTION_RELEASE
&功放;&安培;关键code == Control.Key codes.KEY code_BACK){
Log.d(SampleExtensionService.LOG_TAG,onKey() - 返回按钮截获。);
onBack();
}否则,如果(mCurrentControl!= NULL){
super.onKey(行动,重点code,时间戳);
}
}
/ **
*关闭当前打开的控制扩展。如果上一个控制
*回堆栈打开它,否则扩展关闭。
* /
公共无效onBack(){
Log.v(SampleExtensionService.LOG_TAGonBack);
如果(!mControlStack.isEmpty()){
意图backControl = mControlStack.pop();
ControlExtension newControl = createControl(backControl);
startControl(newControl);
} 其他 {
STO prequest();
}
}
好吧,我想通了这个问题。我不得不添加下面的RegistrationInformation类方法。
@覆盖
公共布尔controlInterceptsBackButton(){
//扩展有它自己的导航,处理回presses。
返回true;
}
在onBack()方法调用STO prequest()是一个终止的延伸。你的情况,你应该只是把自己的逻辑在此方法中,让申通快递prequest()将不会被调用,如果你不需要它。
In control extension for Sony SmartWatch2, I can receive back key through onKey, but how can I prevent extension from terminating? I want to hook back key to do some process, but pressing back key terminates extension.
In SampleAdvancedControlExtension, it seems like it is blocking back button by starting new control, but I'm only using single control.
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();
}
}
Ok, I figured out the problem. I had to add following method in RegistrationInformation class.
@Override
public boolean controlInterceptsBackButton() {
// Extension has it's own navigation, handles back presses.
return true;
}
In "onBack()" method the call to "stopRequest()" is the one that terminates the extension.In your case you should just put your own logic in this method, so that "stopRequest()" won't be called if you don't need it.
这篇关于索尼SmartWatch2:挂钩返回键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!