I'm running an AsyncTask
to retrieve some info via HTTP.
I'm calling this method from my main activity (do_get_from_url()
is triggered by a button click):
private void do_get_from_url() {
new getFromURL(this).execute();
}
The class that this calls is in the same .java
file and starts as follows:
class getFromURL extends AsyncTask<Void, Void, String> {
private MainActivity activity;
getFromURL(MainActivity activity){
this.activity = activity;
}
...other code here...
String linkURL = activity.link_url.getText().toString();
String getFromURLrequestURL = activity.getString(R.string.short_url_request_url_base);
...other code here...
}
It seems that I need to use activity
in order to access both the string resources and the UI element link_url
from the main activity BUT the line this.activity = activity
displays a warning in Android Studio that it is leaking a context.
Is there any way to avoid this?