• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps org.apache.commons.net.ftp.FTPClient.storeFile freezing interaction and animations

thaylin79

Lurker
I'm using org.apache.commons.net.ftp.FTPClient to communicate with an ftp server via an android app I'm making that records video and then uploads it to the ftp server. Everything is fine until I call storeFile at which point the app prevents any interaction until the uploading is completed. Is there any way around this? I'm currently developing for API lvl 12. My set up is as follows I have a class that calls a service in the background to handle recording of the video as well as the ftp setup. In the FTP class I have any of my fptclient interaction within asynctasks. Here is my method for uploading the file:
Code:
public boolean upload(String srcFilePath, String desFileName, String desDirectory)
{
    if(!isLoggedIn())
    {
        return false;
    }
    boolean status = false;
    try
    {
        status = new AsyncTask<String, Void, Boolean>(){
            @Override
            protected Boolean doInBackground(String... args) {
                boolean status = false;
                try {
                    String srcFilePath = args[0];
                    String desFileName = args[1];
                    String desDirectory = args[2];
                    FileInputStream srcFileStream = new FileInputStream(srcFilePath);

                    // change working directory to the destination directory
                    if (changeDirectory(desDirectory,true)) {
                        status = mFTPClient.storeFile(desFileName, srcFileStream);
                    }
                    srcFileStream.close();
                    return status;
                } catch (Exception e) {
                    Log.d(TAG, "upload failed");
                    e.printStackTrace();
                    return false;
                }
            }
         }.execute(srcFilePath, desFileName, desDirectory).get();
    } catch (InterruptedException e)
    {
        e.printStackTrace();
        return status;
    } catch (ExecutionException e)
    {
        e.printStackTrace();
        return status;
    }
    return status;

}
 
I figured it out with some help on stackoverflow. Apparently since I was using .get() it was stopping any processes until the asynctask was completed. I just needed to refactor a bit to call the methods I needed to or dispatch an event through a listener to inform the app that the upload is completed. Hooray!
 
Back
Top Bottom