Wednesday, 30 March 2022

When Intent is received in Xamarin, ensure that only one instance is running at any given time

The Xamarin App sends and receives requests to the "central microservice" every 5 seconds using a timer. We can do an "action" in two ways: using intent from another app or scanning a QR code from a web app. Our app sends a request to the "central microservice" when scanning a QR Code or receiving an Intent, and receives a request from the "central microservice" after "5" seconds.

When scanning a QR code, the "central microservice" sends a single request per call. However, while using Intent from another app, you may receive an additional request. Apps are executing in two instances on Intent.

In the AndroidManifest.xml file, I tried adding android:launchMode="singleInstance" and android:launchMode="singleTask".

In MainActivity.cs, I inserted LaunchMode = LaunchMode.SingleTask and LaunchMode = LaunchMode.SingleInstance.

In Another App (the Intent comes from), I inserted intent.addFlags(Intent.FLAG ACTIVITY REORDER TO FRONT).

Both Apps are still active (can be seen by minimizing the app). How can I ensure that only one instance of the app is running at any given time when the Intent is being received?



from When Intent is received in Xamarin, ensure that only one instance is running at any given time

No comments:

Post a Comment