在键盘服务中我无法启动主要活动:
public void onKey(int primaryCode, int[] keyCodes)
Log.d(TAG, primaryCode + " PrimaryCode to send");
if (primaryCode == 6) {
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
Log.d(TAG, primaryCode + " Greating is command");
}
结果,弹出一个错误
日志猫:
12-03 10:46:07.613: E/InputEventReceiver(2776): Exception dispatching input event.
12-03 10:46:07.613: E/MessageQueue-JNI(2776): Exception in MessageQueue callback: handleReceiveCallback
12-03 10:46:07.613: E/MessageQueue-JNI(2776): android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
12-03 10:46:07.613: E/MessageQueue-JNI(2776): at android.app.ContextImpl.startActivity(ContextImpl.java:944)
12-03 10:46:07.613: E/MessageQueue-JNI(2776): at android.app.ContextImpl.startActivity(ContextImpl.java:931)
12-03 10:46:07.613: E/MessageQueue-JNI(2776): at android.content.ContextWrapper.startActivity(ContextWrapper.java:284)
12-03 10:46:07.613: E/MessageQueue-JNI(2776): at sample.stand.Keyb.onKey(Keyb.java:162)