How to call startActivityForResult in class initialed from layout : main.xml
this is the same question as "how can I retrieve data from the new one to the old one".
But in my first Activity, I called setContentView(R.layout.main);
. There is a surfaceview drawing on canvas.
The only method I know is to call getContext()
to get the context, then call startActivity()
. But I开发者_运维问答 can't call startActivityForResult()
from the context I get, it seems that it doesn't support, I need to call it only in my activity class.
Can anyone give me any opinion?
EDIT:
Here is my code :
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;
}
}
If you are completely sure that getContext() is an instance of an Activity
then you can do:
((Activity)getContext()).startActivityForResult(intent, 0);
Can anyone give me any opinion?
Call startActivityForResult()
from your activity. Have your SurfaceView
or whatever call a method on your activity that triggers the call to startActivityForResult()
.
精彩评论