List of usage examples for android.support.v4.app LoaderManager getLoader
public abstract <D> Loader<D> getLoader(int id);
From source file:com.albedinsky.android.support.universi.UniversiActivityDelegate.java
/** * Starts a loader with the specified <var>id</var>. If there was already started loader with the * same id before, such a loader will be <b>re-started</b>, otherwise new loader will be <b>initialized</b>. * * @param id Id of the desired loader to start. * @param params Params for loader.//from w w w.j av a 2 s .c o m * @param callbacks Callbacks for loader. * @return Initialized or re-started loader instance or {@code null} if the specified <var>callbacks</var> * do not create loader for the specified <var>id</var>. * @see #initLoader(int, android.os.Bundle, android.support.v4.app.LoaderManager.LoaderCallbacks) * @see #restartLoader(int, android.os.Bundle, android.support.v4.app.LoaderManager.LoaderCallbacks) * @see #destroyLoader(int) */ @Nullable public <D> Loader<D> startLoader(@IntRange(from = 0) int id, @Nullable Bundle params, @NonNull LoaderManager.LoaderCallbacks<D> callbacks) { final LoaderManager manager = ((FragmentActivity) mContext).getSupportLoaderManager(); if (manager.getLoader(id) == null) return initLoader(id, params, callbacks); else return restartLoader(id, params, callbacks); }
From source file:com.github.jobs.ui.fragment.JobListFragment.java
private void queryList() { try {/*w ww.ja v a 2 s. c o m*/ FragmentActivity activity = getActivity(); if (activity == null || !isAdded()) { return; } LoaderManager loaderManager = activity.getSupportLoaderManager(); Loader<Object> loader = loaderManager.getLoader(mCurrentSearch.hashCode()); if (loader == null) { loaderManager.initLoader(mCurrentSearch.hashCode(), null, this); } else { loaderManager.restartLoader(mCurrentSearch.hashCode(), null, this); } } catch (IllegalStateException e) { // happens when activity is closed. We can't use isResumed since it will be false when the activity is // not being shown, thus it will cause problems if user loads another screen while this is still loading } }
From source file:nu.firetech.android.pactrack.frontend.ParcelDetailsFragment.java
public void doRefresh() { LoaderManager lm = getLoaderManager(); if (lm.getLoader(REFRESH_LOADER_ID) == null) { lm.initLoader(REFRESH_LOADER_ID, null, this); } else {/* w w w . j a v a 2 s .c om*/ lm.restartLoader(REFRESH_LOADER_ID, null, this); } }
From source file:com.kaliturin.blacklist.fragments.SMSConversationsListFragment.java
private void loadListViewItems(int listPosition, boolean markSeen, boolean showProgress) { if (!isAdded()) { return;/*from ww w.j a va 2 s.c o m*/ } int loaderId = 0; ConversationsLoaderCallbacks callbacks = new ConversationsLoaderCallbacks(getContext(), listView, listPosition, cursorAdapter, markSeen, showProgress); LoaderManager manager = getLoaderManager(); Loader<?> loader = manager.getLoader(loaderId); if (loader == null) { // init and run the items loader manager.initLoader(loaderId, null, callbacks); } else { // restart loader manager.restartLoader(loaderId, null, callbacks); } }
From source file:com.wit.android.support.database.LoadableAssistant.java
/** * Starts a loader using {@link LoaderManager} obtained from the given <var>activity</var> with * the current id and the specified parameters. * <p>/*w ww .ja va 2s. com*/ * If the LoaderManager already has a Loader with the id of this assistant, such a loader will be * restarted by {@link LoaderManager#restartLoader(int, android.os.Bundle, LoaderManager.LoaderCallbacks)}, * otherwise will be initiated by {@link LoaderManager#initLoader(int, android.os.Bundle, LoaderManager.LoaderCallbacks)}. * <p> * <b>Note</b>, that this assistant must have valid (none negative) loader id, otherwise the * requested loader can not be started. * * @param activity Activity used to access LoaderManager instance. * @param params The desired parameters for loader. * @return {@code True} if loader was successfully started (initiated/restarted), {@code false} * otherwise. */ public boolean startLoader(@NonNull FragmentActivity activity, @Nullable Bundle params) { if (mLoaderId >= 0) { final LoaderManager loaderManager = activity.getSupportLoaderManager(); if (loaderManager != null) { if (loaderManager.getLoader(mLoaderId) != null) { loaderManager.restartLoader(mLoaderId, params, this); } else { loaderManager.initLoader(mLoaderId, params, this); } return true; } } return false; }
From source file:com.kaliturin.blacklist.fragments.SMSConversationFragment.java
private void loadListViewItems(int threadId, int unreadCount, int listPosition) { if (!isAdded()) { return;/*from w ww . jav a 2 s .co m*/ } int loaderId = 0; ConversationLoaderCallbacks callbacks = new ConversationLoaderCallbacks(getContext(), threadId, unreadCount, listView, listPosition, cursorAdapter); LoaderManager manager = getLoaderManager(); if (manager.getLoader(loaderId) == null) { // init and run the items loader manager.initLoader(loaderId, null, callbacks); } else { // restart loader manager.restartLoader(loaderId, null, callbacks); } }
From source file:com.zns.comicdroid.activity.Comics.java
private void loadData() { final LoaderManager lm = getSupportLoaderManager(); if (lm.getLoader(LOADER_ID) == null) { lm.initLoader(LOADER_ID, null, this); } else {/*from w ww. ja v a 2 s.c om*/ lm.restartLoader(LOADER_ID, null, this); } }
From source file:info.guardianproject.gpg.KeyListFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); setEmptyText(getString(R.string.search_hint)); setHasOptionsMenu(true);/*from w w w . j a va 2 s . c om*/ mListView = getListView(); mAction = getArguments().getString("action"); // TODO should everything be CHOICE_MODE_MULTIPLE? if (mAction == null || mAction.equals(Action.SHOW_PUBLIC_KEYS)) { mListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); } else if (mAction.equals(Action.FIND_KEYS)) { mListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); } else if (mAction.equals(Action.SELECT_PUBLIC_KEYS)) { mListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); } else if (mAction.equals(Action.SELECT_SECRET_KEYS)) { mListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); } else { mListView.setChoiceMode(ListView.CHOICE_MODE_NONE); } registerReceiver(); handleIntent(mAction, getArguments().getBundle("extras")); LoaderManager lm = getLoaderManager(); if (mAction.equals(Action.FIND_KEYS) && lm.getLoader(Tabs.FIND_KEYS) != null) { lm.initLoader(Tabs.FIND_KEYS, null, this); } }
From source file:com.gbozza.android.popularmovies.fragments.MovieGridFragment.java
/** * A method that invokes the AsyncTask to populate the RecyclerView, * it's based on the sorting option selected by the user. Default is "most popular" *//*from w w w .ja v a 2 s . c o m*/ public void loadCards() { if (null != mSwipeContainer && mSwipeContainer.isRefreshing()) { mSwipeContainer.setRefreshing(false); } if (NetworkUtilities.isOnline(mContext)) { switch (mSorting) { case SORTING_POPULAR: new FetchMoviesTask().execute( new String[] { NetworkUtilities.getMoviedbMethodPopular(), String.valueOf(mPage) }); break; case SORTING_RATED: new FetchMoviesTask() .execute(new String[] { NetworkUtilities.getMoviedbMethodRated(), String.valueOf(mPage) }); break; case SORTING_FAVOURITES: LoaderManager loaderManager = getActivity().getSupportLoaderManager(); if (null == loaderManager.getLoader(ID_FAVOURITES_LOADER)) { loaderManager.initLoader(ID_FAVOURITES_LOADER, null, this); } else { loaderManager.restartLoader(ID_FAVOURITES_LOADER, null, this); } break; } } else { showErrorMessage(R.string.error_no_connectivity, mContext); } }
From source file:nu.firetech.android.pactrack.frontend.ParcelDetailsFragment.java
@Override public void refreshDone() { int[] loaders = { PARCEL_LOADER_ID, EVENTS_LOADER_ID }; LoaderManager lm = getLoaderManager(); for (int loader_id : loaders) { if (lm.getLoader(loader_id) == null) { lm.initLoader(loader_id, null, this); } else {/*w w w .j a v a 2 s .c o m*/ lm.restartLoader(loader_id, null, this); } } }