我希望得到结果形式AsyncTask,我可以用system.out.println()显示,但我希望保留该结果并保存在AsyncTask之外的新属性上;
OnTaskFinished.java
public interface OnTaskFinished
{
public void onFeedRetrieved(String feeds);
}
RetrieveFeedTask.java
class RetrieveFeedTask extends AsyncTask<String, Void, String>
{
String HTML_response= "";
String VideoLink;
public String getVideoLink() {
return VideoLink;
}
public void setVideoLink(String videoLink) {
this.VideoLink = videoLink;
}
OnTaskFinished onOurTaskFinished;
public RetrieveFeedTask(OnTaskFinished onTaskFinished)
{
onOurTaskFinished = onTaskFinished;
}
@Override
protected void onPreExecute()
{
super.onPreExecute();
}
@Override
protected String doInBackground(String... urls)
{
try
{
URL url = new URL(urls[0]); // enter your url here which to download
URLConnection conn = url.openConnection();
// open the stream and put it into BufferedReader
BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String inputLine;
while ((inputLine = br.readLine()) != null)
{
//System.out.println(inputLine);
if(inputLine.toString().contains("<meta property='og:image'"))
{
String str =inputLine;
str = str.replace("<meta property='og:image' content=\"", "");
//System.out.println(str);
VideoLink=str;
setVideoLink(str);
inputLine=str;
}
HTML_response += inputLine;
}
br.close();
//System.out.println("Done");
}
catch (MalformedURLException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
return VideoLink;
}
@Override
protected void onPostExecute(String feed)
{
onOurTaskFinished.onFeedRetrieved(feed);
}
}
这就是我打电话的方式 Main.java
String data;
....
new RetrieveFeedTask(new OnTaskFinished()
{
@Override
public void onFeedRetrieved(String feeds)
{
System.out.println(feeds);
}
}).execute(VideoUrl);
我希望这些Feed可以从RetrieveFeedTask中获取并设置在diferente值之上 在这种情况下,将结果设置为数据;