Skip to content

Commit

Permalink
Added settings to disable threading on the status receiver
Browse files Browse the repository at this point in the history
  • Loading branch information
ltrudu committed Jan 27, 2023
1 parent 6fb02dd commit e9c7954
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,40 +97,59 @@ protected void unRegisterForScannerStatus(DWStatusScannerSettings settings)
}

void registerNotificationReceiver() {
// Ensure that no thread was left running
QuitReceiverThreadNicely();
if(mStatusSettings.mUseSeparateThread) {
// Ensure that no thread was left running
QuitReceiverThreadNicely();

Log.d(TAG, "registerNotificationReceiver()");
broadcastReceiverThread = new HandlerThread(mStatusSettings.mPackageName + ".NOTIFICATION.THREAD");//Create a thread for BroadcastReceiver
Log.d(TAG, "registerNotificationReceiver()");
broadcastReceiverThread = new HandlerThread(mStatusSettings.mPackageName + ".NOTIFICATION.THREAD");//Create a thread for BroadcastReceiver

broadcastReceiverThread.start();
broadcastReceiverThread.start();

broadcastReceiverThreadLooper = broadcastReceiverThread.getLooper();
broadcastReceiverHandler = new Handler(broadcastReceiverThreadLooper);
broadcastReceiverThreadLooper = broadcastReceiverThread.getLooper();
broadcastReceiverHandler = new Handler(broadcastReceiverThreadLooper);

IntentFilter filter = new IntentFilter();
filter.addAction(DataWedgeConstants.NOTIFICATION_ACTION);
mContext.registerReceiver(mStatusBroadcastReceiver, filter, null, broadcastReceiverHandler);
IntentFilter filter = new IntentFilter();
filter.addAction(DataWedgeConstants.NOTIFICATION_ACTION);
mContext.registerReceiver(mStatusBroadcastReceiver, filter, null, broadcastReceiverHandler);
}
else
{
IntentFilter filter = new IntentFilter();
filter.addAction(DataWedgeConstants.NOTIFICATION_ACTION);
mContext.registerReceiver(mStatusBroadcastReceiver, filter);

}
}

void unRegisterNotificationReceiver() {
//to unregister the broadcast receiver
try {
mContext.unregisterReceiver(mStatusBroadcastReceiver); //Android method
}
catch(IllegalArgumentException e)
{
Log.d(TAG, "registerNotificationReceiver(): Trying to unregister a receiver that has not been previously released..");
Log.d(TAG, "registerNotificationReceiver(): Status receiver should be started before trying to stop it.");
//e.printStackTrace();
if(mStatusSettings.mUseSeparateThread) {
//to unregister the broadcast receiver
try {
mContext.unregisterReceiver(mStatusBroadcastReceiver); //Android method
} catch (IllegalArgumentException e) {
Log.d(TAG, "registerNotificationReceiver(): Trying to unregister a receiver that has not been previously released..");
Log.d(TAG, "registerNotificationReceiver(): Status receiver should be started before trying to stop it.");
//e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}

QuitReceiverThreadNicely();
}
catch (Exception e)
else
{
e.printStackTrace();
try {
mContext.unregisterReceiver(mStatusBroadcastReceiver); //Android method
} catch (IllegalArgumentException e) {
Log.d(TAG, "registerNotificationReceiver(): Trying to unregister a receiver that has not been previously released..");
Log.d(TAG, "registerNotificationReceiver(): Status receiver should be started before trying to stop it.");
//e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}

QuitReceiverThreadNicely();

}

private void QuitReceiverThreadNicely() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
package com.zebra.datawedgeprofileintents;

public class DWStatusScannerSettings {

/**
* Set to false to work in the mainthread
*/
public boolean mUseSeparateThread = true;


/*
Set a the package name that will retrieve the scanner status
*/
Expand Down

0 comments on commit e9c7954

Please sign in to comment.