Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8102899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:22:02+00:00 2026-06-05T23:22:02+00:00

I have an AsyncFacebookRunner that uploads an image to Facebook. I want to create

  • 0

I have an AsyncFacebookRunner that uploads an image to Facebook. I want to create a cancel button that will stop the download.

How can one achieve that?

EDIT:

This is how I use it:

byte[] data = null;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
data = baos.toByteArray();
Bundle params = new Bundle();
params.putByteArray("picture", data);
AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(facebook);
mAsyncRunner.request("me/photos", params, "POST", 
new PhotoUploadListener(dialog), null);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T23:22:04+00:00Added an answer on June 5, 2026 at 11:22 pm

    You can always extend the AsyncFacebookRunner class and override the request method.
    Something like this:

    public class CancelableAsyncFacebookRunner extends AsyncFacebookRunner {
        private Thread requestThread;
    
        public AsyncFacebookRunner(Facebook fb) {
            super(fb);
        }
    
        @Override
        public void request(final String graphPath,
                final Bundle parameters,
                final String httpMethod,
                final RequestListener listener,
                final Object state) {
    
            this.requestThread = new Thread() {
                @Override
                public void run() {
                    try {
                        String resp = fb.request(graphPath, parameters, httpMethod);
                        listener.onComplete(resp, state);
                    } catch (FileNotFoundException e) {
                        listener.onFileNotFoundException(e, state);
                    } catch (MalformedURLException e) {
                        listener.onMalformedURLException(e, state);
                    } catch (IOException e) {
                        listener.onIOException(e, state);
                    }
                }
            };
        }
    
        public void cancel() {
            this.requestThread.interrupt();
        }
    }
    

    It hasn’t been tested, but should give you the general idea.


    Edit

    Now that I think about it, this makes little sense, since you want to use the AsyncFacebookRunner to make multiple requests and the cancel will cancel the last request only.

    I would suggest returning the thread and then have the ability to interupt it somewhere else, but you can’t change the signature of the method like this and creating a new method won’t make it possible to use other request methods defined in the AsyncFacebookRunner class.

    Instead you can do something like:

    public class CancelableAsyncFacebookRunner extends AsyncFacebookRunner {
        private Hashtable<String, Thread> requestThreads;
    
        public AsyncFacebookRunner(Facebook fb) {
            super(fb);
            this.requestThreads = new Hashtable<String, Thread>();
        }
    
        @Override
        public void request(final String id, 
                final String graphPath,
                final Bundle parameters,
                final String httpMethod,
                final RequestListener listener,
                final Object state) {
            Thread thread = new Thread() {
                @Override
                public void run() {
                    try {
                        String resp = fb.request(graphPath, parameters, httpMethod);
                        requestThreads.remove(id);
                        listener.onComplete(resp, state);
                    } catch (FileNotFoundException e) {
                        requestThreads.remove(id);
                        listener.onFileNotFoundException(e, state);
                    } catch (MalformedURLException e) {
                        requestThreads.remove(id);
                        listener.onMalformedURLException(e, state);
                    } catch (IOException e) {
                        requestThreads.remove(id);
                        listener.onIOException(e, state);
                    }
                }
            });
    
            this.requestThreads.put(id, thread);
            thread.start();
        }
    
        public void cancel(String id) {
            if (this.requestThreads.containsKey(id) {
                this.requestThreads.get(id).interrupt();
            }
        }
    }
    

    You’ll need to generate an id somehow for the request, can be something simple like:

    String.valueOf(System.currentTimeMillis());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have a look at one of my websites: moskah.com The problem is that it
I have a facebook dialog in the screen in which I put a button
Have one Doubt In MVC Architecture we can able to pass data from Controller
Have data that has this kind of structure. Will be in ascending order by
Have any one tried to activate fancybox thumbnail gallery using a button or an
Have an app that can use tts to read text messages. It can also
have a small javscript that users can include into their sites like so: <script
Have two UIBarButtonItems want to make it as one UIBarButtonItem and toggle between them
Have deployed numerous report parts which reference the same view however one of them
have a problem. At first look at this HTML <div id=map style=background-image: url(map.png); width:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.