Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /////// $$$$$$$$$$$ SYNTAX
- //...
- new AsyncTask<Void, Void, String>() {
- @Override
- protected void onPreExecute() {
- //...
- }
- @Override
- protected String doInBackground(Void... voids) {
- return performBlockingTask();
- }
- @Override
- protected void onProgressUpdate(Integer... progress) {
- mProgessBar.setProgress(progress);
- }
- @Override
- protected void onPostExecute(String result) {
- mTextView.setText(result);
- }
- }.execute();
- //...
- // WORKING EXAMPLE
- new AsyncTask<URL, Integer, Long>() {
- protected Long doInBackground(URL... urls) {
- int count = urls.length;
- long totalSize = 0;
- for (int i = 0; i < count; i++) {
- totalSize += Downloader.downloadFile(urls[i]);
- publishProgress((int) ((i / (float) count) * 100));
- // Escape early if cancel() is called
- if (isCancelled()) break;
- }
- return totalSize;
- }
- protected void onProgressUpdate(Integer... progress) {
- setProgressPercent(progress[0]);
- }
- protected void onPostExecute(Long result) {
- showDialog("Downloaded " + result + " bytes");
- }
- }.execute(url1, url2, url3);
- // Modified Code from google Android API
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement