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 8889917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:22:51+00:00 2026-06-14T22:22:51+00:00

I am a newbie in Android and creating a mini FTP download manager for

  • 0

I am a newbie in Android and creating a mini FTP download manager for myself.. I am using multithreading, each thread to handle one download or upload. In the MainActivity.java, I am using two spinners in the view. One to list the files on the server (which can be downloaded), another to list files on my phone folder (which can be uploaded). I want to update the first (download) spinner when a new file is uploaded, and the second (upload) spinner when a new file is downloaded. However I am not able to make out how to update the spinners only when the corresponding threads finish their job. I created methods to update the spinners in the MainActivity.java and tried to call them in the end of the run() of the threads, so that they’l be updated once the threads finish downloading/uploading. However, I am getting an error in LogCat saying

android.view.ViewRoot$CalledFromWrongThreadException : Only the original thread that created a view hierarchy can touch its views.

The method for updating upload spinner is:

void upScrollUpdate() {
    spinup=(Spinner)findViewById(R.id.uploadspin);
    spinup.setEnabled(false);
    String[] upload={"No Files"};
    File sdDir=Environment.getExternalStorageDirectory();
    File dir=new File (sdDir.getAbsolutePath() + "/aFTP");
    File[] fArray=dir.listFiles();
    if(fArray.length>0) {
        upload=new String[fArray.length];
    }
    for(int i=0;i<fArray.length;i++) {
        upload[i]=fArray[i].getName();
    }
    ArrayAdapter<String> saaUpload=new ArrayAdapter<String>(this,android.R.layout.simple_spinner_dropdown_item,upload);
    spinup.setAdapter(saaUpload);
    if(spinup.getSelectedItem().toString().equalsIgnoreCase("No Files")) {
        uploadButton.setEnabled(false);
    }
    spinup.setEnabled(true);
}

Why cant this method be called from another thread, and what is the other way out of this, I simply want to update the spinners but I have spent a whole day on this only thing…

  • 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-14T22:22:52+00:00Added an answer on June 14, 2026 at 10:22 pm

    For any piece of code that will update the UI, put that in this block:

    Refer to this link for more info on runOnUiThread

    runOnUiThread(new Runnable() {
         public void run() {
    
             // RUN THE CODE WHICH IS GIVING THAT EXCEPTION HERE
    
        }
    });
    

    The same can also be done like this:

    Runnable run = new Runnable() {
    
        @Override
        public void run() {
    
            // RUN THE CODE WHICH IS GIVING THAT EXCEPTION HERE
    
        }
    }; YourActivity.this.runOnUiThread(run);
    

    Alternatively, you can make use of an AsyncTask. You can do your processing in the doInBackground() method and then update the Spinners in the onPostExecute() method of the AsyncTask

    EDIT: Check these tutorials to help you get started with using AsyncTask:

    1. http://www.vogella.com/articles/AndroidPerformance/article.html#asynctask
    2. http://androidresearch.wordpress.com/2012/03/17/understanding-asynctask-once-and-forever/
    3. http://android10.org/index.php/articlesother/239-android-application-and-asynctask-basics
    4. http://mobileorchard.com/android-app-developmentthreading-part-2-async-tasks/
    5. http://thenewboston.org/watch.php?cat=6&number=101

    The 5th link to thenewboston.org has about 200 odd video tutorials on YouTube here: http://www.youtube.com/course?list=EC2F07DBCDCC01493A&feature=plcp

    EDIT 2: Check the edit in this link here: https://stackoverflow.com/a/13265776/450534

    It is at the bottom of the answer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am newbie for Android Development. i don't have any idea for creating Scientific
Android newbie here. I'm using this tutorial to show some rows that I fetch
Android newbie here and would like to create a basic app using the AndriodPlot
I'm newbie to android and present working on android smartphone apps using phonegap and
Hi am newbie to android development. I had created one application where i need
Iam newbie in Android development, and I have one stupid question. Is all pretty
I am and Android/Java newbie and am having trouble creating a GeoPoint when I
I'm a newbie android.I have some problem about my mini app. You can see
[Android Newbie alert] I need to capture the contents of a WebView in a
I am newbie in android, in my android app, a main Activity class, which

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.