java - only the first file gets downloaded -
i have string array , want both files downloaded, reason it's first element of array gets downloaded. first element downloaded dropbox correctly need second 1 later. better if call preworks() function oncreate twice? can problem?
thanks
public void preworks() { asynctask = new asynctask<void, void, void>() { @override protected void doinbackground(void... params) { int count = 0; string[] txt_files = {"/l12.txt", "/l13.txt"}; (string filename : txt_files) { file file = new file(environment.getexternalstoragedirectory() .getabsolutepath() + "/do" + filename); string response = ""; if (!(file.exists())) { //file doesn't exist!! androidauthsession session = null; try { session = buildsession(); } catch (dropboxexception e) { e.printstacktrace(); } dropboxapi = new dropboxapi<>(session); dir.mkdirs(); file filedb = new file(file + filename .substring(filename.lastindexof('.'))); try { fileoutputstream outputstream = new fileoutputstream(filedb); textdownloader.dropboxapi.getfile(filename, null, outputstream, null); return null; } catch (filenotfoundexception e) { e.printstacktrace(); } catch (dropboxexception e) { e.printstacktrace(); } } bufferedreader br; try { br = new bufferedreader(new inputstreamreader(new fileinputstream (file), "cp1252")); (string line; (line = br.readline()) != null; response += line + '\n'); count = response.length() - response.replace(";", "").length(); } catch (filenotfoundexception e) { } catch (ioexception e) { } string prefilename = filename.substring(0, filename.length() - 4); preferencemanager.getdefaultsharedpreferences(textdownloader.this) .edit() .putstring(prefilename, response).apply(); } return null; } @override protected void onpostexecute(void param) { toast.maketext(textdownloader.this, "your file has been downloaded", toast .length_short) .show(); intent intent = new intent(textdownloader.this, mainactivity.class); textdownloader.this.startactivity(intent); } @override protected void onpreexecute() { super.onpreexecute(); //tv1.settext("your file getting downloaded"); toast.maketext(textdownloader.this, "your file getting downloaded", toast.length_short) .show(); } }; asynctask.execute(); }
Comments
Post a Comment