2011-09-16 21 views
2

私のAndroidアプリケーションでは、レンダラーからアクティビティを切り替えたいと思っています。レンダラーを作成すると、コンストラクターにコンテキストが渡されます。Android - レンダラーのアクティビティを切り替える

public MyRenderer(Context ctx){ 

    this.context=ctx; 
} 

public void onDrawFrame(GL10 gl) { 

    testFlag = renderFrame(); 


    if(testFlag > 0) 
    { 
     Intent myIntent = new Intent(this.context, MyActivity.class); 
     myIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
     this.context.startActivity(myIntent); 
     testFlag = 0; 
     return; 
    } 


} 

これはonPause()呼び出し、いくつかのOpenGLのスタッフを扱う私のメインの活動で.. acivities切り替えたとき、私は何を得る

はエラーです:onDrawFrame機能の私のレンダラーに

を(スレッド毎に一度ログイン)なし現在のコンテキストでのOpenGL ES APIへ

コール 01:私は次のエラーが表示されている時点で

誰でもお手伝いできますか? OpenGLへの呼び出しがOpenGLスレッドから作られたものではなく、どうやって解決するのかが原因であることに気付きましたか?

レンダラ内からアクティビティを切り替える適切な方法は何ですか? GLSurfaceView.Rendererドキュメントから

答えて

0

Threading
The renderer will be called on a separate thread, so that rendering performance is decoupled from the UI thread. Clients typically need to communicate with the renderer from the UI thread, because that's where input events are received. Clients can communicate using any of the standard Java techniques for cross-thread communication, or they can use the queueEvent(Runnable) convenience method.

あなたのOpenGLを行うことができるはずはあなたonPause()方法からポスト、などのRunnableて正しく呼び出します。

GLスレッドからアクティビティスイッチを開始しているという事実は問題の一部です(がちょっと変わっているようですが、 ))。

1

私はそれらのソース使用:これは

private Context context; 
    public MyGLRenderer(Context context) { 
    super(); 
    this.context = context;       
} 

(例えばレンダラの)非アクティビティクラスであるクラス内の活動を切り替えること解決する
How can I start an Activity from a non-Activity class?
How do I restart an Android Activity

  Intent myIntent = new Intent(context, MyActivity.class); 
      myIntent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); 
      ((Activity)context).finish(); 
      ((Activity)context).overridePendingTransition(0, 0); 
      context.startActivity(myIntent); 
      ((Activity)context).overridePendingTransition(0, 0); 

関連する問題