I have an application that allows video calls. It works using firebase notification. The flow is
1) push comes 2) PushService starts my CallService. 3) CallService starts IncomingCallActivityby PendingIntent .
pushService -> callService -> callActivity
This approach works if the app is on the foreground or if the app was minimized. But if the app wasn't started at all or closed by the user, the call chain doesn't work. The callActivity doesn't start. Is there any way to start the activity?
val intent = CallActivity.newIntent(this, someExtra)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK)
PendingIntent.getActivity(
this,
123,
intent,
PendingIntent.FLAG_ONE_SHOT
).send()
If your app targets API level 29 or higher, you cannot launch an Activity
from a Service
if the Service
is in the background and the app has not got any existing activities (which is the case when the app is not running, as you've seen). This restriction was added in API level 29 to reduce UI interference from background apps. See https://developer.android.com/guide/components/activities/background-starts for an explanation of the exact conditions that are necessary to allow a background Service
to launch an Activity
.
To verify that this is your problem, change your targetSDK to 28 or lower and see if the problem goes away.