私はAndroid開発の初心者です。この質問が些細なことである場合は、ご容赦ください。
ボタンを含むメイン アクティビティがあります。
<Button
android:id="@+id/single_player"
style="@style/ButtonTheme"
android:text="Single Player"
android:visibility="visible"
android:onClick="OpenGameActivity" />
そして、ボタンがルーティングされるメイン アクティビティ内のメソッド:
public void OpenGameActivity()
{
Intent intent = new Intent(MainActivity.this, GameActivity.class);
startActivity(intent);
}
ここで、GameActivity.class は GLSurfaceView を作成するためのアクティビティです。
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.Renderer の単純な実装である GameRender を作成する GLSurfaceView の単純な実装です。Activity、SurfaceView、Renderer をすべてhttp://developer.android.com/training/graphics/opengl/environment.htmlのガイドに基づいてセットアップしました 。レンダラーは次のようになります。
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
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>