0

I am using the Android USB host and an intent to open an app when a device is connected to the phone. However, if the app is open, I do not want it to open again.

Below is the relevant code from the manifest file:

<intent-filter>
     <action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
 </intent-filter>
 <meta-data
     android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"
     android:resource="@xml/device_filter" />

<intent-filter>
   <action android:name="android.intent.action.MAIN" />
   <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

I have Java code that can detect the device if the app is already open, so no need for the app to open again. In practice, this is just an annoyance. The app is open, and another "copy" opens on top of it.

shurup
  • 751
  • 10
  • 33

1 Answers1

1

Sounds like you need to set a flag in the activity's manifest entry.

Either singleTask or singleInstance, depending on your needs. See the documentation for what each means:

Hope that helps!

dominicoder
  • 9,338
  • 1
  • 26
  • 32