How to call startActivityForResult in a class initialized from layout: main.xml

this is the same question as “how can I extract data from new to old”.

But in my first action I called setContentView(R.layout.main);. The canvas has a view of the surface.

The only method I know is to call getContext()to get the context and then call startActivity(). But I can’t call startActivityForResult()from the context that I get, it seems that it does not 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;
    }
}
+3
source share
2 answers

, getContext() Activity, :

((Activity)getContext()).startActivityForResult(intent, 0);
+7

- - ?

startActivityForResult() . SurfaceView , , startActivityForResult().

+2

Source: https://habr.com/ru/post/1776100/


All Articles