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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T12:54:45+00:00 2026-05-15T12:54:45+00:00

The following code executes a function that retrieves a file via ftp and then

  • 0

The following code executes a function that retrieves a file via ftp and then displays it in an imageview. Since I’m using the main thread the UI locks up, somebody tells me I can use asynctask to make this work but I can’t figure it out :<

Is anybody familiar with this that could offer me some guidance?

package hhh.ggg;

import android.app.Activity;
import android.app.AlertDialog;
import android.os.Bundle;
import android.os.Handler;

import java.io.File;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;
//import it.sauronsoftware.ftp4j.FTPClient;

import it.sauronsoftware.ftp4j.*;


public class hhh extends Activity {
    /** Called when the activity is first created. */
 FTPClient ftp;
 String host = "ipofFTPserver";

  final Handler mHandler = new Handler();
  final Runnable mUpdateResults = new Runnable() {
         public void run() {
             updateResultsInUi();
         }
     };



 @Override

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        startLongRunningOperation();   

 }

 protected void startLongRunningOperation() {

        // Fire off a thread to do some work that we shouldn't do directly in the UI thread
        Thread t = new Thread() {
            public void run() {

             try
             {
             ftp = new FTPClient();
             ftp.connect(host);
             ftp.login("username", "password");
             ftp.changeDirectory("public_ftp");
       ftp.download("test.jpg", new java.io.File("/sdcard/test.jpg")); 
             }
      catch(Exception e)
      {                

      }



                mHandler.post(mUpdateResults);
            }
        };
        t.start();
    }

 private void updateResultsInUi() {

        // Back in the UI thread -- update our UI elements based on the data in mResults


  TextView jpgName = (TextView)findViewById(R.id.jpgname);      
  ImageView jpgView = (ImageView)findViewById(R.id.jpgview);
  String myJpgPath = "/sdcard/test.jpg";              
      jpgName.setText(myJpgPath);
  BitmapFactory.Options options = new BitmapFactory.Options();  
  options.inSampleSize = 2;
  Bitmap bm = BitmapFactory.decodeFile(myJpgPath, options);
  jpgView.setImageBitmap(bm);
    }




}
  • 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-05-15T12:54:45+00:00Added an answer on May 15, 2026 at 12:54 pm

    Hi brux to avoid UI locks up use AsyncTask, you must implement somethin like this.

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);       
       setContentView(R.layout.main);
    
        this.pd = ProgressDialog.show(this, "Working...", "*** Downloading Data...", true, false);
        new DownloadTask().execute(" parameters needed for download");
    }
    
    private class DownloadTask extends AsyncTask<String, Void, Object> {
         protected Void doInBackground(String... args) {
             Log.d("********Jorgesys", "Background thread starting......"); 
             startLongRunningOperation();   
            return null;         
         }
    
         protected void onPostExecute(Object result) {
             Log.d("********Jorgesys", "onPostExecute......");
    
             if (Splash.this.pd != null) {
              Splash.this.pd.dismiss();
             }
             updateResultsInUi();
    
         }
    } 
    
    
    protected void startLongRunningOperation() {
                 try
                 {
                 ftp = new FTPClient();
                 ftp.connect(host);
                 ftp.login("username", "password");
                 ftp.changeDirectory("public_ftp");
           ftp.download("test.jpg", new java.io.File("/sdcard/test.jpg")); 
                 }
          catch(Exception e)
          {                
    
          }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just discovered that the following code executes without error (Chrome): console.log(fa); function fa(){}
I have the following thread code which executes correct first time. After that from
I have the following line of code that executes properly except for one hitch.
I have used following code to create a simple PDF file. It executes fine
I am using jQuery Address Plugin and I have the following code. $.address.change(function(e) {
I have the following code in main.js : (function($) { // Code goes here
When I put the following code within the $(document).ready(function () {} it executes correctly.
The following code executes without error and prints In some , which means that
I have the following code that executes a C++ program and outputs it :
I have tomcat 6.0 with 2 webapps. One of them executes the following code:

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.