So, I did not receive ACTION_USB_DEVICE_DETACHED Intent to go to LauncherActivity ; I don’t know what the deal is, perhaps something that I misunderstand about intent filters or Activity callbacks.
The solution I used comes from a post related to Pratik. Basically, I took all USB_DEVICE_DETACHED from AndroidManifest.xml . Then, in the onCreate method of Service I registered a BroadcastReceiver as follows:
@Override public void onCreate() { detachReceiver = new BroadcastReceiver() { public void onReceive(Context context, Intent intent) { if(intent.getAction().equals(UsbManager.ACTION_USB_DEVICE_DETACHED)) stopSelf(); } }; IntentFilter filter = new IntentFilter(); filter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED); registerReceiver(detachReceiver, filter); }
A bit inconvenient, and I'm still wondering why just adding USB_DEVICE_DETACHED to the <intent-filter> from LauncherActivity didn't work, but it does what I need.
source share