从Libgdx推出Android意图渲染方法 [英] Launch Android Intent from Libgdx render method
问题描述
我想从libgdx渲染方法,启动意图,但我得到一个无法创建内螺纹的处理程序已经不叫活套。prepare()的错误。
I'm trying to launch an Intent from the render method in libgdx but I am getting a "Can't create handler inside thread that has not called Looper.prepare()" error.
我已经实现从这里接口<一个href=\"http://$c$c.google.com/p/libgdx-users/wiki/IntegratingAndroidNativeUiElements3TierProjectSetup\" rel=\"nofollow\">http://$c$c.google.com/p/libgdx-users/wiki/IntegratingAndroidNativeUiElements3TierProjectSetup
我用吐司implementaion和工作好。
I have used the Toast implementaion and that works okay.
这是我的Android执行
This is my Android implementation
@Override
public void launchPlayerRoom() {
Intent intent = new Intent(appContext, RoomViewActivity.class);
intent.putExtras(selectPlayerRoom());
startActivity(intent);
}
和来自Libgdx调用render
and calling from Libgdx render
if (health_amount <= 0){
actionResolver.launchPlayerRoom();
}
意图需要,因为它取决于正在递减在呈现一个值被从渲染调用。
据我所知,这个问题是调用由渲染线程(我想!)UI线程,但我不知道如何解决它。
我从这个职位<一试href=\"http://stackoverflow.com/questions/6213538/cant-create-handler-inside-thread-that-has-not-called-looper-$p$ppare\">Can't创建内螺纹已不叫活套。prepare处理器()
@Override
public void launchPlayerRoom() {
final Intent intent = new Intent(appContext, RoomViewActivity.class);
intent.putExtras(selectPlayerRoom());
runOnUiThread(new Runnable() {
@Override
public void run() {
startActivity(intent);
}
});
但是,这并没有区别。
But this makes no difference.
任何帮助将是最AP preciated。
Any help would be most appreciated.
推荐答案
该Libgdx渲染线程不是Android的UI线程,因此当你调用在Android后端code,需要在Android UI线程上下文你必须通过一些跳铁圈。
The Libgdx "render" thread is not the Android "UI" thread, so when you invoke code in the Android back-end that requires the Android UI thread context you have to jump through some hoops.
在一般情况下,该解决方案是创建一个处理程序
在UI线程的上下文,然后张贴的Runnable到该对象。这是上集成的Android UI元素的wiki页面正在做什么。
In general, the solution is to create a Handler
in the context of the UI thread and then post Runnables to that object. This is what the wiki page on integrating android UI elements is doing.
如果您有吐司
实施工作正常,那么意图
code也应努力(包括有相同的要求,对Android UI线程上下文中运行)。
If you have the Toast
implementation working correctly, then the Intent
code should also work (both have the same requirement to be run on the Android UI thread context).
或许有一些其他问题的处理程序
你创建(难道不是正在Libgdx期间创建创建
回调?(其隐含地创建它的线程关联)。或者,你在你的安装太早调用此code?一个完整的回溯可能会提供更多的细节。
Perhaps there is some other problem with the Handler
you're creating (is it not being created during the Libgdx create
callback? (Its implicitly associated with the thread that created it.) Or are you invoking this code too early in your setup? A full backtrace might provide more details.
这篇关于从Libgdx推出Android意图渲染方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!