2012-02-06 4 views
0

나는 게임을 개발 중이며 플레이어가 실패하거나 완료되면 플레이어 점수와 버튼을 다시 시작하는 게임을 시작하려고하지만 NullPointerException을 throw합니다. 여기 내 코드가있다. 뭐가 잘못 됐어.Android : OpenGL 렌더러에서 활동 시작

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> 

답변

1

스레드에서 메소드 onDrawFrame 작업 GLThread. 비 UI 스레드에서 활동을 시작할 수 없습니다.

1

startActivity()는 활동에서 사용할 수 있습니다. 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); 
} 
관련 문제