I am wondering if there is a good way to return an object from a running thread. In my android project (not important for the question) I have this method:
public void getFolders()
{
    Thread t = new Thread(new Runnable() 
    {
        @Override
        public void run() 
        {
            List<File> result = new ArrayList<File>();
            Files.List request = null;
            do 
            {
                try 
                {
                    request = service.files().list();
                    request.setQ("'appdata' in parents");
                    FileList files = request.execute();
                    result.addAll(files.getItems());
                    request.setPageToken(files.getNextPageToken());
                } 
                catch (IOException e) 
                {
                    System.out.println("An error occurred: " + e);
                    request.setPageToken(null);
                }
            } 
            while (request.getPageToken() != null && request.getPageToken().length() > 0);
        }   
    });
    t.start();
}
This method grabs some data from the internet and store the result in List<File> result. That's why I do not want to run it in the UI thread. Now I want to return this List to my main method. What is the best way to do this?
 
     
     
     
    