Android: Which Launch Mode is best for Activity with Foreground Service and Broadcast Receiver?

53 Views Asked by At

I'm confused with the launchMode options for the Manifest file, even with the description on the Android page.

My goal is to develop an app, that sends a notification after a certain amount of unlocks per time (30mins), but also after a certain screen time. Therefore, in onCreate of the MainActivity, a foregroundService is started, which is supposed to constantly run in the background. To listen to the user actions, I have registered an IntentFilter with the corresponding actions and my BroadcastReceiver class in MainActivity. In my Receiver class, I catch the actions in if-conditions.

I only have two Acitivities, LoginActivity -> MainActivity, which holds the foregroundService and several Receivers.

It seems that my MainActivity is created several times in the whole process. And it seems that with this, my Receiver-class also triggers multiple times, which I want to avoid to prevent errors. So I'm wondering, which launch mode do I need for my MainActivity?

Maybe you need completely different informations, then I'm happy to share them!

0

There are 0 best solutions below