How do I pass an intent from an activity to a class extending surfaceview?
Heres the code that sends out the intent:
btnCutOutter.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
//Send intent to cut image from user selection path
//See designCanvas.java for details
String optionSelected = "Yes";
Intent myIntent = new Intent(view.getContext(), designCanvas.class);
myIntent.putExtra("id",optionSelected );
}
});
When I try to retrieve the intent data :
public class designCanvas extends SurfaceView implements SurfaceHolder.Callback {
//Create shape using Path
Path mPath = new Path();
private drawThread _thread;
private ArrayList<GraphicObject> _graphics = new ArrayList<GraphicObject>();
public designCanvas(Context context, AttributeSet attributes) {
super(context, attributes);
getHolder().addCallback(this);
setFocusable(true);
_thread = new drawThread(getHolder(), this);
String optionSelected = getIntent().getStringExtra("id");
. . .
I am informed by eclipse that :
The method getIntent() is undefined
I would be very grateful if someone could give me so guidance on this 🙂
Many thanks.
Any view in an android is contained within an activity, therefore the activity has a reference to the view (in this case a SurfaceView). So its simply a matter of getting the intent data in the Activity then using a setter for the data you want to pass to the SurfaceView
So in the Activity that holds the SurfaceView call getIntent like you have in your question then call a setter in the SurfaceView eg.
mySurfaceView.setSomeValue(someValue)EDIT
You are calling getIntent() in the designCanvas class it needs to be called in the Activity thats holds SurfaceView