2015-09-06 43 views
3

我的應用程序是一個OpenGL ES 2.0的應用程序,並且因此,具有2周需要的螺紋(UI線程和GL螺紋)正確開始從非活動類的意圖

我具有延伸活性和從類在那裏我可以輕鬆地開始像這樣意圖:

Public class MainActivity extends Activity{ 

    public void goToSomeWebsite(){ 

     startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(webAddress))); 

    } 
} 

現在,我有另一個類,這是一個基本場景,我有這個類的方法的onTouchEvent以及渲染方法和其他一些方法。所以,onTouchEvent運行在UI線程和render方法(和其他)上,在GL線程上運行。

所以我的課會是這樣的:

public class MyScene implements Scene(){ 

    @Override 
    public void render(){ 
     //Render something here 
    } 

    @Override 
    public void updateLogiC(){ 
     //Do some other work here 
    } 

    @Override 
    public boolean onTouchEvent(MotionEvent event){ 
     //Handle touch events 
     return false; 
    } 
} 

從上面的類,這將是啓動這個其他意圖正確的(安全)的方式?

無論我是從GL線程(比如上面的updateLogic)還是從UI線程(如上面的onTouchEvent方法)開始它都有問題嗎?

目前,我有一個手柄的活動,並簡單的做這樣的事情:

activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(webAddress))); 

,它工作正常(這是從GL線程中完成的),但是,直覺告訴我這ISN」完成這一任務的正確方法。

回答

0

如果你的類提供上下文,應用程序等等你可以很容易做到這樣

getContext().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://stackoverflow.com/"))); 

getApplication().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://stackoverflow.com/")));