You could try any of the two approaches :
1. inside MyActivity create a method which return "this" . i.e
Activity getActivity(){
return this;
}
and then call this method from anonymous method.
new MyTask(getActivity()).execute(val);
2. or you can use this to access the "this" .
OuterClass.this
In your case
new MyTask(MyActivity.this).execute(val);