android - cordova 3.0 FileWriter THREAD WARNING: exec() call to File.write blocked the main thread...should use CordovaInterface.getThreadPool() -


i'm using filewriter , works fine except these messages in logcat when write largish files of various sizes upto 3mb.

i had @ fileutils.java source , write function doesn't use getthreadpool() interface (the reader does).

as test thought i'd adapt filewriter use runnable interface , able code compile , execute - unfortunately logcat messages still show up...

the blocking times between 25ms , 1200ms far. haven't run serious comparison tests determine if change makes real difference - looking absence of logcat messages.

would these changes below make real difference?

are these message should worry about?

my java pretty basic - here changes made - following reader implementation.

else if (action.equals("write")) {     this.write(args.getstring(0), args.getstring(1), args.getint(2), args.getboolean(3), callbackcontext); } /* original code else if (action.equals("write")) {     long filesize = this.write(args.getstring(0), args.getstring(1), args.getint(2), args.getboolean(3));     callbackcontext.sendpluginresult(new pluginresult(pluginresult.status.ok, filesize)); 

} */

and in write function below...

public void write(string filename, final string data, final int offset, final boolean isbinary, final callbackcontext callbackcontext) throws filenotfoundexception, ioexception, nomodificationallowedexception { if (filename.startswith("content://")) {     throw new nomodificationallowedexception("couldn't write file given content uri"); }  final string fname = filehelper.getrealpath(filename, cordova);  this.cordova.getthreadpool().execute(new runnable() {     public void run() {         log.d(log_tag, "starting write");         try {             boolean append = false;             byte[] rawdata;             if (isbinary) {                 rawdata = base64.decode(data, base64.default);             } else {                 rawdata = data.getbytes();             }             bytearrayinputstream in = new bytearrayinputstream(rawdata);             fileoutputstream out = new fileoutputstream(fname, append);             byte buff[] = new byte[rawdata.length];             in.read(buff, 0, buff.length);             out.write(buff, 0, rawdata.length);             out.flush();             out.close();             log.d(log_tag, "ending write");             callbackcontext.sendpluginresult(new pluginresult(pluginresult.status.ok, rawdata.length));         } catch (ioexception e) {             log.d(log_tag, e.getlocalizedmessage());             callbackcontext.sendpluginresult(new pluginresult(pluginresult.status.io_exception, not_readable_err));         }     } }); 

}

yes, these messages important , should use background thread complicated tasks, such file writing. reason of problem these tasks blocking cordova , experience example ui lags.

if next actions dependent on task being completed, recommend using callback method.


Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -