gpt4 book ai didi

android - 异步任务不允许我覆盖 onPostExecute(方法不会覆盖其父类(super class)中的方法)

转载 作者:行者123 更新时间:2023-11-29 15:04:45 25 4
gpt4 key购买 nike

我正在创建一个应用程序来抓取 YouTube 上的播放列表列表。它曾经是一个视频列表,但我更改了代码,现在它不允许我覆盖该方法。

我的理解是我应该用新的播放列表值而不是像以前那样用视频更改“扩展 AsyncTask”,但它仍然不起作用。

它是:

public abstract class GetPlaylistAsyncTask extends AsyncTask<String, Void, Pair<String, List<Video>>> {

现在是:

public abstract class GetPlaylistAsyncTask extends AsyncTask<String, Void, Pair<String, List<Playlist>>> {

这是错误的地方:

mPlaylist = new Playlist(mPlaylistId);
initAdapter(mPlaylist);
new GetPlaylistAsyncTask(mYouTubeDataApi, mTitle, mSearchQuery) {
@Override
public void onPostExecute(Pair<String, List<Playlist>> result) {
handleGetPlaylistResult(mPlaylist, result);
}
}.execute(mPlaylist.playlistId, mPlaylist.getNextPageToken());

这是 AsyncTask:

public abstract class GetPlaylistAsyncTask extends AsyncTask<String, Void, Pair<String, List<Playlist>>> {
private static final String TAG = "GetPlaylistAsyncTask";
private static final Long YOUTUBE_PLAYLIST_MAX_RESULTS = 50L;

private static final String YOUTUBE_VIDEOS_PART = "snippet,contentDetails,statistics"; // video resource properties that the response will include.
private static final String YOUTUBE_VIDEOS_FIELDS = "items(id,snippet(title,description,thumbnails/high),contentDetails/duration,statistics)"; // selector specifying which fields to include in a partial response.

private YouTube mYouTubeDataApi;
private String mTitle;
private String mSearchQuery;

public GetPlaylistAsyncTask(YouTube api, String title, String searchQuery) {
mYouTubeDataApi = api;
mTitle = title;
mSearchQuery = searchQuery;
}

@Override
protected Pair<String, List<Playlist>> doInBackground(String... params) {

SearchListResponse searchResponse;
try {
YouTube.Search.List search = mYouTubeDataApi.search().list("id,snippet");

search.setKey(ApiKey.YOUTUBE_API_KEY);
search.setQ(mTitle + " " + mSearchQuery);

search.setType("video");
search.setFields("items(id/kind,id/videoId,snippet/title,snippet/thumbnails/default/url)");
search.setMaxResults(YOUTUBE_PLAYLIST_MAX_RESULTS);
searchResponse = search.execute();
} catch (IOException e) {
e.printStackTrace();
return null;
}

if (searchResponse == null) {
Log.e(TAG, "Failed to get playlist");
return null;
}

ArrayList videoIds = new ArrayList();

for (SearchResult item : searchResponse.getItems()) {
videoIds.add(item.getId().getVideoId());
}
VideoListResponse videoListResponse = null;
try {
videoListResponse = mYouTubeDataApi.videos()
.list(YOUTUBE_VIDEOS_PART)
.setFields(YOUTUBE_VIDEOS_FIELDS)
.setKey(ApiKey.YOUTUBE_API_KEY)
.setId(TextUtils.join(",", videoIds)).execute();
} catch (IOException e) {
e.printStackTrace();
}

return new Pair(searchResponse.getNextPageToken(), videoListResponse.getItems());
}
}

我不明白我的代码有什么问题,如果您能指出正确的方向,我将不胜感激。提前致谢!

最佳答案

我想通了。 “onPostExecute”接受 doInBackground 返回的对象,正如这篇文章所说:

stackoverflow post

感谢大家的回答,尤其是@Enzokie

关于android - 异步任务不允许我覆盖 onPostExecute(方法不会覆盖其父类(super class)中的方法),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38928321/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com