EMDKManager.getEMDKManager() is locking my GUI thread. Workarounds?

J Jon-Luke West 3 years 7 months ago
30 2 0

Hello,
 
I am writing an Android application using the EMDK.  I am noticing that the end of the EMDKManager.getEMDKManager() method is holding up my GUI when launching an activity or adding a fragment to an activity.  This causes an awkward delay between a method being called to interface with the device and the GUI being displayed telling the user what is happening.  (roughly 1 second)  I have been playing with different threading architectures in order to circumvent this, but I am out of ideas.  In the following example, I am adding a fragment to the current activity which performs a an unlock of the cradle the device is in using the EMDK, displays a screen saying that is what is happening and then cleans itself up after 15 seconds. (Timing is handled by the parent activity.)
 
public class myFragment extends Fragment         implements EMDKManager.EMDKListener {      private EMDKManager manager = null;      private static final String LOGTAG = "FRAGMENT";      private Handler myHandler = null;       @Override     public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {          Log.v(LOGTAG, "Creating View");         return inflater.inflate(R.layout.activity_unlock,container,false);     }     @Override     public void onResume() {           super.onResume();           EMDKManager.getEMDKManager(getActivity().getApplicationContext(), this);     }     @Override     public void onStop() {         Log.v(LOGTAG, "Stopping");         if(manager != null) {             Log.v(LOGTAG, "Releasing EMDK");             manager.release();             manager = null;         }         super.onStop();     }            @Override     public void onClosed() {           Log.v(LOGTAG, "Releasing EMDK");         manager.release();     }        @Override     public void onOpened(EMDKManager emdkManager) {         this.manager = emdkManager;         myHandler = new Handler();         myHandler.post(threadAction);     }      private Runnable threadAction = new Runnable() {         @Override         public void run() {             //Perform Action             MC18Device.cmd_UnlockCradle(manager,10,500,500,true);              final ToneGenerator tg = new ToneGenerator(AudioManager.STREAM_SYSTEM, 100);             tg.startTone(ToneGenerator.TONE_PROP_BEEP);         }      }; }         }     };  
 
I notice that the EMDK unlock command that I make occurs before the layout of the fragment is actually displayed on the screen.  I have traced this to the EMDKManager.getEMDKManager() method.  It seems to be holding the GUI thread until it finishes whatever it is doing between onOpened() and returning to fragment.onResume(), but I cannot figure out an effective method of pushing this to another thread so the GUI displays before the unlock or as the unlock is taking place.  Does anyone have any recommendations?

Please Register or Login to post a reply

2 Replies

Y Yanis Dalabiras

Jon-Luke,  the service manager will always return on the main thread, there is no work around to avoid the blocking  main thread.  Moving the getEMDKManger() call to your OnCreate could save some time, as it would only be done once.

J Jon-Luke West

I have managed to push the getEMDKManager() method to a new thread that is created in onResume(), but the method is still hanging my system/UI thread.  My onResume looks like this:

@Overridepublic void onResume() {

   super.onResume();
  Log.v(LOGTAG, "Starting");
   new Thread(initEMDK).start();
}

and I am still experiencing a delay in the GUI display.  Only when removing the call to get the EMDKManager does this delay go away.

Thoughts?

CONTACT
Can’t find what you’re looking for?