android - Cardboard sample, method must be called from UI thread -


trying develop app google cardboard, downloaded sample official sdk. in inner class imageloadertask ( should helper class manage threading )

    class imageloadertask extends asynctask<pair<uri, options>, void, boolean> {      /**      * reads bitmap disk in background , waits until it's loaded pano widget.      */     @override     protected boolean doinbackground(pair<uri, options>... fileinformation) {       options panooptions = null;  // it's safe use null vrpanoramaview.options.       inputstream istr = null;       if (fileinformation == null || fileinformation.length < 1           || fileinformation[0] == null || fileinformation[0].first == null) {         assetmanager assetmanager = getassets();         try {           istr = assetmanager.open("andes.jpg");           panooptions = new options();           panooptions.inputtype = options.type_stereo_over_under;         } catch (ioexception e) {           log.e(tag, "could not decode default bitmap: " + e);           return false;         }       } else {         try {           istr = new fileinputstream(new file(fileinformation[0].first.getpath()));           panooptions = fileinformation[0].second;         } catch (ioexception e) {           log.e(tag, "could not load file: " + e);           return false;         }       }        panowidgetview.loadimagefrombitmap(bitmapfactory.decodestream(istr), panooptions);       try {         istr.close();       } catch (ioexception e) {         log.e(tag, "could not close input stream: " + e);       }        return true;     }   } 

panowidgetview widget panorama, , declared inside activity includes inner class. android studio gives me error: method loadimagefrombitmap must called ui thread, inferred thread worker. possible solution?

try moving "loadimagefrombitmap" inside onpostexecute :

class imageloadertask extends asynctask<pair<uri, bitmapfactory.options>, void, boolean> {         options panooptions = null;  // it's safe use null vrpanoramaview.options.         inputstream istr = null;          /**          * reads bitmap disk in background , waits until it's loaded pano widget.          */         @override         protected boolean doinbackground(pair<uri, bitmapfactory.options>... fileinformation) {              if (fileinformation == null || fileinformation.length < 1                     || fileinformation[0] == null || fileinformation[0].first == null) {                 assetmanager assetmanager = getassets();                 try {                     istr = assetmanager.open("andes.jpg");                     panooptions = new options();                     panooptions.inputtype = options.type_stereo_over_under;                 } catch (ioexception e) {                     log.e(tag, "could not decode default bitmap: " + e);                     return false;                 }             } else {                 try {                     istr = new fileinputstream(new file(fileinformation[0].first.getpath()));                     panooptions = fileinformation[0].second;                 } catch (ioexception e) {                     log.e(tag, "could not load file: " + e);                     return false;                 }             }              try {                 istr.close();             } catch (ioexception e) {                 log.e(tag, "could not close input stream: " + e);             }              return true;         }          @override         protected void onpostexecute(boolean aboolean) {             if( istr!=null && panooptions!=null){                  panowidgetview.loadimagefrombitmap(bitmapfactory.decodestream(istr), panooptions);             }             super.onpostexecute(aboolean);         }     } 

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -