Reputation: 2131
I have a foreground service that calls StartActivity on ActivityA. If ActivityA is not in the foreground, it is displayed to the user. If the Activity is in the foreground, the service still calls StartActivity, and the activity receives a new Intent and updates itself accordingly.
The user may interact with ActivityA which will display ActivityB as a popup (Theme.Dialog), during which ActivityA is paused. Now if the service detects another event, it calls StartActivity again. This time though, I do not want to navigate to ActivityA. I want the user to still see the ActivityB popup and have ActivityA update itself in the background.
Is there any flags I could add to the intent which the service starts which will prevent navigation to ActivityA if it is Started but Paused?
Other Info :
1. If I have ActivityA bring ActivityB back to the foreground, ActiviyB end up flickering and just doesn't look good.
2. Have the service use ActivityManager to determine if ActivityB is displayed. If it is, broadcast an intent which will be listened to by ActivityA and force it to update, instead of calling StartService. But this couples the Service with two activites, needs more coding, and will force me to synchronize the service call onto the main thread to avoid timing issues.
I am really hoping there is something simple that I can do like set some flag on the intent. Or catch the intent within ActivityA, update the activity, but cancel the intent to prevent the screen navigation.
Any suggestions?
Note: Not using Android notification bar. Understand that starting activities from service is not recommended. We have a specific need for this.
Upvotes: 0
Views: 210
Reputation: 1242
Yes you can, if you are binding your service.. call bindService(mConn); in onResume() of your activity and unBindService(mConn); in onPause()..And in your service class, @Override the onUnbind() method and you can set the flag there.
I hope it was useful.
Upvotes: 0
Reputation: 1750
It sounds like you might want to use AtomicReference from java.util.concurrent.atomic to pass the right intent to start activity. I haven't actually tried this, but its probably a good place to start.
Upvotes: 0