I have an application that is launched via an intent-filter
action. The problem is that every time the event/ action occurs, Android displays a dialog asking to launch the app even if it is already started.
I want the behavior to be as follows:
Is there a way to achieve both of these goals? I am targeting Android 4.0.
edit
Here is my intent filter:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
</intent-filter>
<intent-filter>
<action android:name="android.hardware.usb.action.USB_DEVICE_DETACHED" />
</intent-filter>
<meta-data
android:name="android.hardware.usb.action.USB_DEVICE_DETACHED"
android:resource="@xml/device_filter" />
Typically, one activity in an app is specified as the main activity, which is the first screen to appear when the user launches the app. Each activity can then start another activity in order to perform different actions.
If you want to make Login activity your main activity then put the the intent-filter tag inside Login activity. Any activity your want to make your main activity must contain intent-filter tag with action as main and category as launcher.
Specifically, there are three key lifecycle methods that deal with when an activity becomes visible or invisible to the user: onStart() , onStop() , and onRestart() . Just as with onCreate() and onDestroy() , your activity inherits them from the Android Activity class.
You need to set the Activity
's launchMode
to singleTask
. You can do this by adding the activity attribute in your Android Manifest:
android:launchMode="singleTask"
See the documentation for more details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With