- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我有一个 GDK 应用程序在 XE12 中运行良好,但现在在转换到 GDK:19 后在 XE16 中崩溃。特别是,在 Activity 中调用 openOptionsMenu()
(在这种情况下,打开 Live Card 上的选项菜单)会导致 BadTokenExceptions。
Logcat 输出:
04-16 03:36:43.197: E/AndroidRuntime(2465): FATAL EXCEPTION: main
04-16 03:36:43.197: E/AndroidRuntime(2465): Process: com.voidstar.glass.sample.pinDrop, PID: 2465
04-16 03:36:43.197: E/AndroidRuntime(2465): java.lang.RuntimeException: Unable to resume activity {com.voidstar.glass.sample.pinDrop/com.voidstar.glass.sample.pinDrop.MenuActivity}: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running?
04-16 03:36:43.197: E/AndroidRuntime(2465): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2828)
04-16 03:36:43.197: E/AndroidRuntime(2465): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2857)
04-16 03:36:43.197: E/AndroidRuntime(2465): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2290)
04-16 03:36:43.197: E/AndroidRuntime(2465): at android.app.ActivityThread.access$800(ActivityThread.java:138)
04-16 03:36:43.197: E/AndroidRuntime(2465): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1236)
04-16 03:36:43.197: E/AndroidRuntime(2465): at android.os.Handler.dispatchMessage(Handler.java:102)
04-16 03:36:43.197: E/AndroidRuntime(2465): at android.os.Looper.loop(Looper.java:149)
04-16 03:36:43.197: E/AndroidRuntime(2465): at android.app.ActivityThread.main(ActivityThread.java:5061)
04-16 03:36:43.197: E/AndroidRuntime(2465): at java.lang.reflect.Method.invokeNative(Native Method)
04-16 03:36:43.197: E/AndroidRuntime(2465): at java.lang.reflect.Method.invoke(Method.java:515)
04-16 03:36:43.197: E/AndroidRuntime(2465): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794)
04-16 03:36:43.197: E/AndroidRuntime(2465): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:610)
04-16 03:36:43.197: E/AndroidRuntime(2465): at dalvik.system.NativeStart.main(Native Method)
04-16 03:36:43.197: E/AndroidRuntime(2465): Caused by: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running?
04-16 03:36:43.197: E/AndroidRuntime(2465): at android.view.ViewRootImpl.setView(ViewRootImpl.java:561)
04-16 03:36:43.197: E/AndroidRuntime(2465): at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:259)
04-16 03:36:43.197: E/AndroidRuntime(2465): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
04-16 03:36:43.197: E/AndroidRuntime(2465): at com.android.internal.policy.impl.PhoneWindow.openPanel(PhoneWindow.java:693)
04-16 03:36:43.197: E/AndroidRuntime(2465): at com.android.internal.policy.impl.PhoneWindow.openPanel(PhoneWindow.java:555)
04-16 03:36:43.197: E/AndroidRuntime(2465): at android.app.Activity.openOptionsMenu(Activity.java:2878)
04-16 03:36:43.197: E/AndroidRuntime(2465): at com.voidstar.glass.sample.pinDrop.MenuActivity.onResume(MenuActivity.java:71)
04-16 03:36:43.197: E/AndroidRuntime(2465): at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1194)
04-16 03:36:43.197: E/AndroidRuntime(2465): at android.app.Activity.performResume(Activity.java:5316)
04-16 03:36:43.197: E/AndroidRuntime(2465): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2818)
04-16 03:36:43.197: E/AndroidRuntime(2465): ... 12 more
服务中将 Activity 绑定(bind)到 Live Card 的方法:
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
// This method is called whenever the Glassware is invoked via voice commands or the OK Glass menu.
if (mLiveCard == null) {
Log.d(TAG, "Connecting mLocationManager");
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_COARSE);
PinDropLocationListener listener = new PinDropLocationListener();
locationListeners.add(listener);
mLocationManager.requestSingleUpdate(criteria, listener, null);
mLiveCard = new LiveCard(getBaseContext(), LIVE_CARD_TAG);
mLiveCard.setViews(new RemoteViews(getPackageName(), R.layout.activity_waiting));
mLiveCard.attach(this); // Prevent this Service from being killed to free up memory
Intent menuIntent = new Intent(this, MenuActivity.class); // Since menus can only be attached to Activities, we create an activity to own and launch the menu.
menuIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
mLiveCard.setAction(PendingIntent.getActivity(this, 0, menuIntent, 0)); // This Intent will be fired whenever the LiveCard is tapped.
Log.d(TAG, "Publishing LiveCard");
mLiveCard.publish(PublishMode.REVEAL); // Add the LiveCard to the Timeline and switch to it
Log.d(TAG, "Done publishing LiveCard");
} else {
mLiveCard.navigate(); // Switch to the app if it's already running
}
return START_STICKY; // No idea what this does. Your guess is as good as mine.
}
还有有问题的 Activity:
/**
* Activity showing the options menu.
*/
public class MenuActivity extends Activity {
// This is technically an Immersion!
// Because Services have no UI, we need to open this Activity, which in turn opens its menu!
PinDropService.MenuBinder mBinder;
private static String TAG = "PinDropMenu";
boolean hasLocation;
/*
* Links this Activity to the Service that spawned it, so the Menu can send and receive information
*/
private ServiceConnection mConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
if (service instanceof PinDropService.MenuBinder) {
mBinder = (PinDropService.MenuBinder)service;
hasLocation = mBinder.hasLocation();
Log.d(TAG, hasLocation ? "Received has location" : "Received no location");
//openOptionsMenu();
}
}
@Override
public void onServiceDisconnected(ComponentName name) {}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
bindService(new Intent(this, PinDropService.class), mConnection, 0);
}
@Override
public void onResume() {
super.onResume();
openOptionsMenu();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.pindropmenu, menu);
return true;
}
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
if (!hasLocation) {
menu.findItem(R.id.directions).setVisible(false);
menu.findItem(R.id.remember).setVisible(false);
}
else {
menu.findItem(R.id.directions).setVisible(true);
menu.findItem(R.id.remember).setVisible(true);
}
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection.
switch (item.getItemId()) {
case R.id.directions:
mBinder.startNavigation();
return true;
case R.id.remember:
mBinder.addToTimeline(); // TODO: Add Mirror functionality!
return true;
case R.id.stop: // IT IS CRITICALLY IMPORTANT TO ADD THIS OR THE GLASSWARE CAN'T BE KILLED IN USERSPACE!
stopService(new Intent(this, PinDropService.class));
return true;
default:
return super.onOptionsItemSelected(item);
}
}
@Override
public void onOptionsMenuClosed(Menu menu) {
// Nothing else to do, closing the Activity.
finish();
}
@Override
public void onStop() {
super.onStop();
unbindService(mConnection); // Don't leak Services!
}
}
点击 Live Card 会导致立即崩溃,并且会转储上面的 Logcat 输出。奇怪的是,如果注释掉的 openOptionsMenu() 未被注释掉并且现有的 openOptionsMenu() 被注释掉,那么第一次点击实际上会打开菜单。第二次尝试打开菜单将失败,并显示类似的 Logcat 输出(BadTokenException 是主要异常,而不是 RuntimeException 上的内部异常)。
最佳答案
来自 skylight1 中 dario 的回答,
“示例也已更新 - 来自 Compass:”
@Override
public void onAttachedToWindow() {
super.onAttachedToWindow();
mAttachedToWindow = true;
openOptionsMenu();
}
泰达里奥!
关于android - 在 XE16 中调用 openOptionsMenu() 导致 WindowManager.BadTokenException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23103736/
我正在构建一个使用 Oracle 数据库 10g 作为数据库后端的 Web 应用程序。我意识到 Express 版本有限制,但我只是想确保连接数不是其中之一。 Oracle 快捷版 (XE) 是否限制
我是一名开始使用 Oracle 数据库的新手,在将 Oracle XE 11g x64 的最新版本安装到 Microsoft Windows 7 x64 Enterprise 时遇到了问题。 安装过程
我有一个 USB 连接到 device发出串行信息。当我运行下面的 Python 脚本(在 Jupyter Notebook 中)时,我从中得到了奇怪的信息。 import serial ser =
我们有一台运行 Delphi XE Professional 的机器,它会在 IDE 中键入时更改某些键的值。它将字母和数字键更改为数字。按下下一个键将按顺序输入下一个数字,直到 9,然后从 0 重新
从昨天开始,我的源代码中的所有蓝点(编译行)都移动了一行。因此,第一个点从“var”而不是“begin”开始,最后一个点是函数最后一个“end”之前的一行。 我删除了除 DPR、PAS、DFM 和 D
我在 RegexBuddy 中构建了一个匹配模式,其行为完全符合我的预期。但我无法将其转移到 Delphi XE,至少在使用最新内置的 TRegEx 或 TPerlRegEx 时是这样。 我的现实世界
TBytes 变量的正确使用模式是什么?根据我的理解,TBytes不是一个类,而是一个“动态字节数组”。我不确定内存在哪里分配,何时释放,以及将其从生产者传递到消费者的最佳方式是什么。我希望我的生产者
我创建了一个自定义 MSBuild .targets我通过 IDE 将其包含在 Delphi XE 项目中,并从项目管理器的上下文菜单中启用它。尽管文件有效,但在我重新保存项目文件后它总是被禁用。 这
有谁知道 http://reportman.sourceforge.net/可用于 Delphi XE 吗? 最佳答案 我已经成功获得Reportmanager 2.9b通过将以下行添加到文件 rpc
Oracle XE Oracle是这样介绍XE的:11g XE(Express Edition)简化版是在Oracle11gR2基础之上一个入门级的小体量数据库,免费用于开发/部署与发布,下载很快
我已经安装了 docker 在 Ubuntu 21.10 并跟随官方 instructions 我拉甲骨文 11g xe 图片:docker pull oracleinanutshell/oracle
一段时间以来,我一直在寻找解决问题的方法,但似乎没有任何效果,这是我重新安装之前的最后一次尝试。 我今天通过其安装向导安装了 Oracle XE 11g 第 2 版,并且一切顺利。我似乎遇到的麻烦是我
我需要模拟汽车在平方区域上移动(比方说)。 任何人都可以轻松想象计算(x/y 坐标、轨迹、速度、加速度、暂停......) 之前的版本(跨千年错误开发...... 21 年前)运行到 Applicat
我已经下载了适用于 Windows 64 位的 Oracle XE 18c,并尝试将其安装在 Windows 10 机器上。我检查了 SHA-256 校验和,它是正确的。 安装开始正常,但是当它复制新
我需要通过客户端操作删除服务器上的物理文件,然后将文件删除事件通知远程数据库-希望这完全在serverSide上发生。 更高版本的Delphi公开了许多以前在WinAPI调用中被锁定的目录服务。目前,
这几年来我一直没有使用Delphi(我使用的最新版本是D2005),现在我需要在DelphiXE中做一些工作。我的问题是,如何在Delphi IDE中禁用声明包装?目前,我使用Modelmaker的代
如何打开应用程序初始化所在的程序单元?我需要进行一些更改。 另外,除了显示的当前单位以外,还可以在程序中搜索所有单位吗? Delphi 5有一个弹出窗口,您可以选择它。 最佳答案 每个项目均由sing
如何配置Datasnap REST服务器(在Windows上作为服务运行)以处理Delphi XE中的https调用?周围有什么好的例子吗? 向上的Delphi XE2似乎具有其他组件-这是否意味着X
我尝试以这种方式列出程序: type TProc = procedure of object; TMyClass=class private fList:Tlist; function getItem
我刚刚发现了 Delphi 的实时绑定(bind)。并创建了我的第一个组件来处理变频器的控制字。该组件本身似乎在表单设计器中测试它效果很好。但是,编译和运行应用程序不起作用。来自 livbinding
我是一名优秀的程序员,十分优秀!