Android:从 opengl rendererr 启动活动

发布于 2025-01-03 02:00:33 字数 836 浏览 1 评论 0原文

我正在开发游戏,我正在尝试启动一项活动,当玩家失败或完成关卡时,显示玩家得分和重新启动游戏的按钮,但它会抛出 NullPointerException。这是我的代码。有什么问题吗?

    public class MyRenderer extends Activity implements Renderer {
    @Override
public void onDrawFrame(GL10 gl) {
       ...............
       if(..............) startActivity(new Intent("android.intent.action.RESTART"));
       ...............
       }
    }


    <activity
        android:name=".Restart"
        android:label="@string/app_name" 
        android:screenOrientation="portrait"
        android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen">
        <intent-filter>
            <action android:name="android.intent.action.RESTART" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

I'm developing game and i'm trying to start an activity that shows players score and button for restart game, when player fail or complete level, but it throws NullPointerException. Here is my code. what's wrong with it.

    public class MyRenderer extends Activity implements Renderer {
    @Override
public void onDrawFrame(GL10 gl) {
       ...............
       if(..............) startActivity(new Intent("android.intent.action.RESTART"));
       ...............
       }
    }


    <activity
        android:name=".Restart"
        android:label="@string/app_name" 
        android:screenOrientation="portrait"
        android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen">
        <intent-filter>
            <action android:name="android.intent.action.RESTART" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

﹎☆浅夏丿初晴 2025-01-10 02:00:33

startActivity() 在 Activity 中可用。 GLSurfaceView 是一个视图。

试试这个:

public class YourRenderer implements GLSurfaceView.Renderer{
.....
.....
private Context mContext;

public YourRenderer(Context context){
mContext = context;
}

public onDrawFrame(Gl10 gl){
if(some statement){
Intent intent = new Intent(...);
mContext.startActivity(intent);
}

startActivity() is available in Activity. GLSurfaceView is a View.

Try this:

public class YourRenderer implements GLSurfaceView.Renderer{
.....
.....
private Context mContext;

public YourRenderer(Context context){
mContext = context;
}

public onDrawFrame(Gl10 gl){
if(some statement){
Intent intent = new Intent(...);
mContext.startActivity(intent);
}
断舍离 2025-01-10 02:00:33

方法onDrawFrame工作在线程GLThread中。您无法从非 UI 线程启动 Activity。

Method onDrawFrame work in thread GLThread. You can't start Activity from non UI thread.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文