EMDK initialization fail

Hi,

 

I have two activities using EMDK. In the first one I initialize EMDK in onCreate method, this works properly. In this first activity I have a button, that starts another activity like this:

 

public void btnDoneOnClick(View view) {

        Intent intent = new Intent(this, LocationUnitsListActivity.class);

        intent.putExtra(Constants.LocationKey, barcode);

        intent.putExtra(Constants.LocationOption, selectedOption);

        startActivity(intent);

        //finish();

    }

 

In onDestroy method of this first activity I do this:

 

@Override

    protected void onDestroy() {

        super.onDestroy();

        if (emdkManager != null) {

 

 

            // Clean up the objects created by EMDK manager

            emdkManager.release();

            emdkManager = null;

        }

    }

 

In the new started activity (the second one) I initialize EMDK again. No error occurs during initialization but barcode scanner stays inactive. So I tried to uncomment last line of the btnDonOnClick method. This made a little progress. Barcode reader is active now also in second activity but in this second activity listener's event DoScannerDataPostExecute is not fired. So the scanned barcodes goes to nowhere and I am not able to catch them in my activity.

 

Here is architecture of my application:

 

class EMDKBaseActivity{

     protected void initializeEMDK(){

          EMDKResults results = EMDKManager.getEMDKManager(

                getApplicationContext(), this);

 

             if (results.statusCode != EMDKResults.STATUS_CODE.SUCCESS) {

                 Toast t = Toast.makeText(this, "EMDKManager Request Failed", Toast.LENGTH_LONG);

                 t.show();

             }

     }

 

     public void onOpened(EMDKManager emdkManager){

      ....

     }

 

     public void onClosed(){

          ...

     }

 

     public void onStatus(StatusData sd){

          ...

     }

 

     public void onData(ScanDataCollection scanDataCollection){

          new AsyncScannerDataUpdate().execute(scanDataCollection);

     }

    

     protected void onStop(){

          ...

     }

 

     @Override

    protected void onDestroy() {

        super.onDestroy();

        if (emdkManager != null) {

 

 

            // Clean up the objects created by EMDK manager

            emdkManager.release();

            emdkManager = null;

        }

    }

}

 

    private class AsyncScannerDataUpdate extends AsyncTask<ScanDataCollection, Void, ArrayList<String>> {

 

 

        @Override

        protected ArrayList<String> doInBackground(ScanDataCollection... params) {

            ArrayList<String> result = new ArrayList<String>();

 

 

            try {

                // Starts an asynchronous Scan. The method will not turn ON the

                // scanner. It will, however, put the scanner in a state in

                // which

                // the scanner can be turned ON either by pressing a hardware

                // trigger or can be turned ON automatically.

                scanner.read();

 

 

                ScanDataCollection scanDataCollection = params[0];

 

 

                // The ScanDataCollection object gives scanning result and the

                // collection of ScanData. So check the data and its status

                if (scanDataCollection != null

                        && scanDataCollection.getResult() == ScannerResults.SUCCESS) {

 

 

                    ArrayList<ScanData> scanData = scanDataCollection

                            .getScanData();

 

 

                    // Iterate through scanned data and prepare the statusStr

                    for (ScanData data : scanData) {

                        // Get the scanned data

                        String barcodeData = data.getData();

                        result.add(barcodeData);

                    }

                }

 

 

            } catch (ScannerException e) {

                // TODO Auto-generated catch block

                e.printStackTrace();

            }

 

 

            // Return result to populate on UI thread

            return result;

        }

 

 

        @Override

        protected void onPostExecute(ArrayList<String> result) {

            DoScannerDataPostExecute(result);

        }

    }

 

 

class FirstActivity extends EMDKBaseActivity{

     public void onCreate(Bundle icicle) {

        super.onCreate(icicle);

 

          ....

 

        initializeEMDK();

    }

 

@Override

 

    protected void DoScannerDataPostExecute(ArrayList<String> result) {

          //this works correctly

    }

 

     public void btnDoneOnClick(View view) {

        Intent intent = new Intent(this, SecondActivity.class);

        startActivity(intent);

        finish();

    }

}

 

class SecondActivity extends EMDKBaseActivity{

     public void onCreate(Bundle icicle) {

        super.onCreate(icicle);

 

          ....

 

        initializeEMDK(); //no error occurs

    }

 

    protected void DoScannerDataPostExecute(ArrayList<String> result) {

          //this DOES NOT work at all. This is not even fired

    }

 

}