<分区>
我是 Android 开发的新手。如果这个问题微不足道,请耐心等待。
我有一个包含按钮的主要 Activity :
<Button
android:id="@+id/single_player"
style="@style/ButtonTheme"
android:text="Single Player"
android:visibility="visible"
android:onClick="OpenGameActivity" />
以及主 Activity 中的一个方法,用于将按钮路由到:
public void OpenGameActivity()
{
Intent intent = new Intent(MainActivity.this, GameActivity.class);
startActivity(intent);
}
现在,GameActivity.class 是一个用于创建 GLSurfaceView 的 Activity :
import android.app.Activity;
import android.opengl.GLSurfaceView;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.NavUtils;
import android.view.MenuItem;
public class GameActivity extends Activity {
private GLSurfaceView GridView;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Create a GLSurfaceView instance and set it
// as the ContentView for this Activity.
GridView = new GameView(this);
setContentView(GridView);
}
GameView 是 GLSurfaceView 的简单实现,它创建 GameRender,GLSurfaceView.Renderer 的简单实现。我根据 http://developer.android.com/training/graphics/opengl/environment.html 上的指南设置了 Activity、SurfaceView 和 Renderer。 渲染器看起来像这样:
import android.opengl.GLES20;
import android.opengl.GLSurfaceView;
import javax.microedition.khronos.opengles.GL10;
public class GameRender implements GLSurfaceView.Renderer {
@Override
public void onDrawFrame(GL10 unused) {
// Redraw background color
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
}
@Override
public void onSurfaceCreated(GL10 gl10, javax.microedition.khronos.egl.EGLConfig eglConfig) {
GLES20.glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
}
@Override
public void onSurfaceChanged(GL10 gl10, int width, int height) {
GLES20.glViewport(0, 0, width, height);
}
}
问题是,每次我从我的 Android 手机上点击应该启动新 Activity 的按钮时,应用程序都会崩溃。我做错了什么?
我在发布这个之前做了我的研究,所以为了澄清我确实将新 Activity 添加到 list 中:
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".GameActivity"
android:parentActivityName=".MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>