當前位置: 首頁>>代碼示例>>Java>>正文


Java AsyncTaskLoader類代碼示例

本文整理匯總了Java中android.support.v4.content.AsyncTaskLoader的典型用法代碼示例。如果您正苦於以下問題:Java AsyncTaskLoader類的具體用法?Java AsyncTaskLoader怎麽用?Java AsyncTaskLoader使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


AsyncTaskLoader類屬於android.support.v4.content包,在下文中一共展示了AsyncTaskLoader類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onCreateLoader

import android.support.v4.content.AsyncTaskLoader; //導入依賴的package包/類
@Override
public Loader<List<Anime>> onCreateLoader(int id, Bundle args) {
    Loader<List<Anime>> loader = new AsyncTaskLoader<List<Anime>>(getActivity()) {
        @Override
        public List<Anime> loadInBackground() {
            List<Anime> animeList = ParseManager.getInstance(getActivity()).getAnimeList(mCurrentPage);
            List<Anime> cacheAnimeList = new ArrayList<>();
            List<Anime> nonCachedAnimeList = new ArrayList<>();
            Anime cachedAnime = null;
            for (Anime anime : animeList) {
                cachedAnime = MAVApplication.getInstance().getRepository().getAnimeByUrl(anime.getUrl());
                if (cachedAnime != null) {
                    AnimeHelper.update(anime, cachedAnime);
                    cacheAnimeList.add(cachedAnime);
                } else {
                    nonCachedAnimeList.add(anime);
                }
            }
            MAVApplication.getInstance().getRepository().updateAnimeList(cacheAnimeList);
            MAVApplication.getInstance().getRepository().insertAnimeList(nonCachedAnimeList);
            return animeList;
        }
    };
    loader.forceLoad();
    return loader;
}
 
開發者ID:SalmanTKhan,項目名稱:MyAnimeViewer,代碼行數:27,代碼來源:ParseAnimeListFragment.java

示例2: onCreateLoader

import android.support.v4.content.AsyncTaskLoader; //導入依賴的package包/類
@Override
public Loader<MapCatalog> onCreateLoader(int id, Bundle args) {
    final ApplicationEx app = ApplicationEx.getInstance(MapListFragment.this.getActivity());
    switch(id){
        case LOCAL_CATALOG_LOADER:
            return new AsyncTaskLoader<MapCatalog>(getActivity()) {
                @Override
                public MapCatalog loadInBackground() {
                    return app.getLocalMapCatalogManager().getMapCatalog();
                }
            };
        case REMOTE_CATALOG_LOADER:
            return new AsyncTaskLoader<MapCatalog>(getActivity()) {
                @Override
                public MapCatalog loadInBackground() {
                    return app.getRemoteMapCatalogProvider().getMapCatalog(false);
                }
            };
    }
    return null;
}
 
開發者ID:RomanGolovanov,項目名稱:ametro,代碼行數:22,代碼來源:MapListFragment.java

示例3: onCreateLoader

import android.support.v4.content.AsyncTaskLoader; //導入依賴的package包/類
@Override
public Loader<List<SocialSpaceInfo>> onCreateLoader(int id, Bundle args) {
  return new AsyncTaskLoader<List<SocialSpaceInfo>>(this) {
    @Override
    public List<SocialSpaceInfo> loadInBackground() {
      List<SocialSpaceInfo> spacesNames = new ArrayList<SocialSpaceInfo>();
      if (SocialServiceHelper.getInstance().spaceService == null) {
        Log.e(LOG_TAG, "Cannot retrieve spaces. Social Space service is null.");
        return null;
      }
      List<RestSpace> spaces = SocialServiceHelper.getInstance().spaceService.getMySocialSpaces();
      String currentServer = AccountSetting.getInstance().getDomainName();
      for (RestSpace space : spaces) {
        SocialSpaceInfo sp = new SocialSpaceInfo();
        sp.displayName = space.getDisplayName();
        sp.name = space.getName();
        sp.avatarUrl = currentServer + space.getAvatarUrl();
        sp.groupId = space.getGroupId();
        spacesNames.add(sp);
      }
      return spacesNames;
    }
  };
}
 
開發者ID:paristote,項目名稱:mobile-android-studio,代碼行數:25,代碼來源:SpaceSelectorActivity.java

示例4: onCreateLoader

import android.support.v4.content.AsyncTaskLoader; //導入依賴的package包/類
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    PoemLog.i(this, "onCreateLoader");
    
    String text = null;
    if (args != null) {
        text = args.getString(PoemConstant.QUERY);
    }

    final String finalText = text == null ? null : text.trim();
    Loader<Cursor> loader = new AsyncTaskLoader<Cursor>(getActivity()) {
        @Override
        public Cursor loadInBackground() {
            return onQuery(finalText);
        }

        @Override
        protected void onStartLoading() {
            forceLoad();
        }
    };
    return loader;
}
 
開發者ID:ManfredVon,項目名稱:Poem,代碼行數:24,代碼來源:BasePoemFragment.java

示例5: onCreateLoader

import android.support.v4.content.AsyncTaskLoader; //導入依賴的package包/類
@Override
public Loader<List<Post>> onCreateLoader(int id, Bundle args) {
    return new AsyncTaskLoader<List<Post>>(getContext()) {
        @Override
        public List<Post> loadInBackground() {
            List<Post> data = new ArrayList<>();

            try {
                data =  Api.getPosts();
            } catch (IOException e) {
                e.printStackTrace();
            }

            return data;
        }
    };
}
 
開發者ID:dwa012,項目名稱:CSCI4669-Fall15-Android,代碼行數:18,代碼來源:MainActivityFragment.java

示例6: createLoader

import android.support.v4.content.AsyncTaskLoader; //導入依賴的package包/類
@Override
protected AsyncTaskLoader<ListData> createLoader(int id, Bundle args) {
    ItemsLoader loader = null;
    if (id == ItemsLoader.ID) {
        boolean needLoadRepImage;
        if (!Client.getInstance().getLogined()){
            getPreferences().edit().putBoolean("needLoadRepImage", false).remove("repPlusImage").apply();
            needLoadRepImage = false;
        }else {
            needLoadRepImage = getPreferences().getBoolean("needLoadRepImage", false);
        }

        setLoading(true);
        loader = new ItemsLoader(getActivity(), args, needLoadRepImage);

    }
    return loader;
}
 
開發者ID:slartus,項目名稱:4pdaClient-plus,代碼行數:19,代碼來源:UserReputationFragment.java

示例7: onCreateLoader

import android.support.v4.content.AsyncTaskLoader; //導入依賴的package包/類
@Override
public Loader<AccessToken> onCreateLoader(int id, Bundle args) {
	// show ProgressDialog
	mProgressDialog = new ProgressDialog(mContext);
	mProgressDialog.setTitle(R.string.dialog_title_text);
	mProgressDialog.setMessage(mContext
			.getString(R.string.dialog_message_text));
	mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
	mProgressDialog.setCancelable(false);
	mProgressDialog.show();

	// run AsyncTaskLoader
	AsyncTaskLoader<AccessToken> loader = new TwitterOAuthAccessTokenLoader(
			mContext, mTwitter, mPin);
	loader.startLoading();
	return loader;
}
 
開發者ID:rsato,項目名稱:android-sample-twitter4j-auth,代碼行數:18,代碼來源:TwitterOAuthAccessTokenCallbacks.java

示例8: onCreateLoader

import android.support.v4.content.AsyncTaskLoader; //導入依賴的package包/類
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    return new AsyncTaskLoader<Cursor>(getActivity()) {

        Cursor mTaskDAta = null;

        @Override
        protected void onStartLoading() {
            if (mTaskDAta != null) {
                notifyLoaderChangeListener();
            } else {
                forceLoad();
            }
        }

        private void notifyLoaderChangeListener() {

        }

        @Override
        public Cursor loadInBackground() {
            //to do Make it private again
            try {
                return getActivity().getContentResolver().query(TaskItemsContract.TaskItemsColumns.CONTENT_URI,
                        null,
                        null,
                        null,
                        null);

            } catch (Exception e) {
                Log.e(TAG, "Failed to asynchronously load data.");
                e.printStackTrace();
                return null;
            }
        }
    };
}
 
開發者ID:vixir,項目名稱:Perfect-Day,代碼行數:38,代碼來源:ListTasksFragment.java

示例9: onCreateLoader

import android.support.v4.content.AsyncTaskLoader; //導入依賴的package包/類
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    return new AsyncTaskLoader<Cursor>(getActivity()) {

        Cursor mTaskDAta = null;

        @Override
        protected void onStartLoading() {
            if (mTaskDAta != null) {
                notifyLoaderChangeListener();
            } else {
                forceLoad();
            }
        }

        private void notifyLoaderChangeListener() {
        }

        @Override
        public Cursor loadInBackground() {
            try {
                Uri todayUri = TaskItemsContract.TaskItemsColumns.CONTENT_URI.buildUpon().appendPath(TaskItemsContract.TaskItemsColumns.COLUMN_NAME_IS_TODAY).appendPath("1").build();
                return getActivity().getContentResolver().query(todayUri,
                        null,
                        null,
                        null,
                        null);

            } catch (Exception e) {
                Log.e(TAG, "Failed to asynchronously load data.");
                e.printStackTrace();
                return null;
            }
        }
    };
}
 
開發者ID:vixir,項目名稱:Perfect-Day,代碼行數:37,代碼來源:TodayTasksFragment.java

示例10: onCreateLoader

import android.support.v4.content.AsyncTaskLoader; //導入依賴的package包/類
/**
 * Instantiates and returns a new AsyncTaskLoader with the given ID.
 * This loader will return task data as a Cursor or null if an error occurs.
 *
 * Implements the required callbacks to take care of loading data at all stages of loading.
 */
@Override
public Loader<Cursor> onCreateLoader(int id, final Bundle loaderArgs) {

    return new AsyncTaskLoader<Cursor>(this) {

        // Initialize a Cursor, this will hold all the task data
        Cursor mTaskData = null;

        // onStartLoading() is called when a loader first starts loading data
        @Override
        protected void onStartLoading() {
            if (mTaskData != null) {
                // Delivers any previously loaded data immediately
                deliverResult(mTaskData);
            } else {
                // Force a new load
                forceLoad();
            }
        }

        // loadInBackground() performs asynchronous loading of data
        @Override
        public Cursor loadInBackground() {
            // Will implement to load data
            return null;
        }

        // deliverResult sends the result of the load, a Cursor, to the registered listener
        public void deliverResult(Cursor data) {
            mTaskData = data;
            super.deliverResult(data);
        }
    };

}
 
開發者ID:fjoglar,項目名稱:android-dev-challenge,代碼行數:42,代碼來源:MainActivity.java

示例11: onCreateLoader

import android.support.v4.content.AsyncTaskLoader; //導入依賴的package包/類
@Override
public Loader<List<OfflineHistoryRecord>> onCreateLoader(int arg0, Bundle arg1) {
    AsyncTaskLoader<List<OfflineHistoryRecord>> loader = new AsyncTaskLoader<List<OfflineHistoryRecord>>(getActivity()) {
        @Override
        public List<OfflineHistoryRecord> loadInBackground() {
            return MAVApplication.getInstance().getRepository().getOfflineHistoryRecords();
        }
    };
    // This is called when a new Loader needs to be created.  This
    // sample only has one Loader with no arguments, so it is simple.
    loader.forceLoad();
    return loader;
}
 
開發者ID:SalmanTKhan,項目名稱:MyAnimeViewer,代碼行數:14,代碼來源:OfflineHistoryMaterialFragment.java

示例12: onCreateLoader

import android.support.v4.content.AsyncTaskLoader; //導入依賴的package包/類
@Override
public Loader<List<HistoryRecord>> onCreateLoader(int arg0, Bundle arg1) {
    Loader<List<HistoryRecord>> loader = new AsyncTaskLoader<List<HistoryRecord>>(getActivity()) {
        @Override
        public List<HistoryRecord> loadInBackground() {
            return MAVApplication.getInstance().getRepository().getHistoryRecords();
        }
    };
    // This is called when a new Loader needs to be created.  This
    // sample only has one Loader with no arguments, so it is simple.
    loader.forceLoad();
    return loader;
}
 
開發者ID:SalmanTKhan,項目名稱:MyAnimeViewer,代碼行數:14,代碼來源:HistoryMaterialFragment.java

示例13: onCreateLoader

import android.support.v4.content.AsyncTaskLoader; //導入依賴的package包/類
@Override
public Loader<String> onCreateLoader(int id, Bundle args) {
    AsyncTaskLoader<String> loader = new AsyncTaskLoader<String>(getActivity()) {
        @Override
        public String loadInBackground() {
            Parser parser = Parser.getExistingInstance(anime.getUrl());
            videoUrl = parser.getEpisodeVideo(episode.getUrl());
            WriteLog.appendLog("VideoDetailsFragment", "loadInBackground " + videoUrl);
            return videoUrl;
        }
    };
    loader.forceLoad();
    return loader;
}
 
開發者ID:SalmanTKhan,項目名稱:MyAnimeViewer,代碼行數:15,代碼來源:VideoDetailsFragment.java

示例14: onCreateLoader

import android.support.v4.content.AsyncTaskLoader; //導入依賴的package包/類
@Override
public Loader<String> onCreateLoader(int id, Bundle args) {
    AsyncTaskLoader<String> loader = new AsyncTaskLoader<String>(this) {
        @Override
        public String loadInBackground() {
            Parser parser = Parser.getExistingInstance(anime.getUrl());
            videoUrl = parser.getEpisodeVideo(episode.getUrl());
            WriteLog.appendLog(mTag, "loadInBackground " + videoUrl);
            return videoUrl;
        }
    };
    loader.forceLoad();
    return loader;
}
 
開發者ID:SalmanTKhan,項目名稱:MyAnimeViewer,代碼行數:15,代碼來源:VideoPlayerActivity.java

示例15: onCreateLoader

import android.support.v4.content.AsyncTaskLoader; //導入依賴的package包/類
@Override
public Loader<String> onCreateLoader(int id, final Bundle args) {
    return new AsyncTaskLoader<String>(mContext) {

        private String mResponse;

        @Override
        protected void onStartLoading() {
            if (args == null) return;
            if (mResponse == null) {
                forceLoad();
            } else {
                deliverResult(mResponse);
            }
        }

        @Nullable
        @Override
        public String loadInBackground() {
            URL url = (java.net.URL) args.getSerializable(URL_EXTRA);
            if (url != null) {
                try {
                    Log.i(TAG, "Requesting Data From: " + url.toString());
                    return HTTPUtils.getHTTPResponse(url);
                } catch (IOException e) {
                    Log.e(TAG, e.getMessage());
                }
            }
            return null;
        }

        @Override
        public void deliverResult(@Nullable String data) {
            super.deliverResult(data);
            mResponse = data;
        }
    };
}
 
開發者ID:scaffeinate,項目名稱:Inflix,代碼行數:39,代碼來源:NetworkLoader.java


注:本文中的android.support.v4.content.AsyncTaskLoader類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。