@@ -37,6 +37,7 @@ public class HCEService extends HostApduService implements HCEServiceCallback {
3737 private static final String TAG = "HCEService" ;
3838
3939 private boolean isForeground ;
40+ private volatile boolean isDeactivated ;
4041 private String backgroundSessionUUID ;
4142 private RTNHCEAndroidModule hceModule ;
4243 private byte [] pendingCAPDU ;
@@ -118,6 +119,7 @@ public void onBackgroundHCEFinish(String handle) {
118119 HeadlessJsTaskContext headlessJsTaskContext = Companion .getInstance (reactContext );
119120 headlessJsTaskContext .finishTask (taskId );
120121 taskSessionIdMap .remove (handle );
122+ stopSelf ();
121123 }
122124
123125 @ Override
@@ -144,6 +146,11 @@ public void onRespondAPDU(String handle, String rapdu) {
144146 @ Override
145147 public byte [] processCommandApdu (byte [] command , Bundle extras ) {
146148 Log .d (TAG , "HCEService:processCommandApdu" );
149+
150+ if (isDeactivated ) {
151+ onCreate ();
152+ }
153+
147154 String capdu = BinaryUtils .ByteArrayToHexString (command ).toUpperCase (Locale .ROOT );
148155
149156 if (isForeground ) {
@@ -181,6 +188,7 @@ public void onCreate() {
181188 }
182189
183190 isForeground = isAppOnForeground (getApplicationContext ());
191+ isDeactivated = false ;
184192 pendingCAPDU = null ;
185193 hceModule = null ;
186194 needsResponse = false ;
@@ -242,6 +250,7 @@ public void onHeadlessJsTaskFinish(int i) {
242250 public void onDeactivated (int reason ) {
243251 Log .d (TAG , "HCEService:onDeactivated: " + reason );
244252 needsResponse = false ;
253+ isDeactivated = true ;
245254
246255 if (isForeground ) {
247256 if (this .hceModule != null && this .hceModule .isHCEActiveConnection ()) {
0 commit comments