当前位置: 首页>>代码示例>>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;未经允许,请勿转载。