這與「如何從新到舊數據檢索數據」的問題相同。如何在佈局中初始化的類中調用startActivityForResult:main.xml
但在我的第一個活動中,我撥打了setContentView(R.layout.main);
。在畫布上有一個表面視圖。
我知道的唯一方法是致電getContext()
獲取上下文,然後致電startActivity()
。但我不能從我得到的上下文中調用startActivityForResult()
,似乎它不支持,我只需要在我的活動類中調用它。
任何人都可以給我意見嗎?
編輯:
這裏是我的代碼:
public class gameView extends SurfaceView implements SurfaceHolder.Callback
{
public gameView(Context context, AttributeSet attrs)
{
//This is how I do :
Intent intent = new Intent();
intent.setClass(getContext(), inputCharactorName.class);
getContext().startActivity(intent);
//This what I WANT to , but I don't know how
//Activity.startActivityForResult(null,FPS);
//I want to start the activity here;
}
}
我不知道我理解你的問題,但嘗試'getApplicationContext()' – cristis 2010-11-21 18:59:34
發表一些代碼可以證明你有問題,這可能會幫助人們理解和回答(從問題中,我不知道你在問什麼,也許代碼會有幫助)。 – 2010-11-21 19:11:29
我使用view.getContext()來返回視圖的上下文。但是不可能調用startActivityForResult()。我不知道爲什麼 – 2010-11-22 04:14:32