Reputation: 1
I have an activity which i call from service, I am using startActivity(intent) to achieve it, it works fine when i am triggering it for the first time, the activity gets launched properly. But if I press the home button on android device and than again try to run that activity from service, activity does not run.
When trying to run it for second time, it triggers 'onDestroy' event, but does not launch the activity after that.
Below is my activity launch code -
`Intent intent = new Intent(this, MyActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.putExtra("type", "LAUNCH");
intent.putExtra("title", "some value");
intent.putExtra("body", "some value");
intent.putExtra("data", "some value");
startActivity(intent);`
Below is my activity snippet from AndroidManifest.xml
file -
<activity
android:name=".MyActivity"
android:launchMode="singleTask"
android:taskAffinity=""
android:excludeFromRecents="true"
android:screenOrientation="portrait"
android:foregroundServiceType="phoneCall"
android:showOnLockScreen="true"
android:showWhenLocked="true"
android:turnScreenOn="true"
android:directBootAware="true"
android:enabled="true"
android:exported="false"
android:supportsPictureInPicture="true"
android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation|keyboardHidden" />
There are no errors in logcat. Tried a lot of flag combinations and launchmodes, still no use.
UPDATE
I want functionality same as WhatsApp Call, where if user1 makes an audio(voice) call to user2, after voice call connects, if user2 puts that activity in background (by pressing home button), no activity is visible in recent activity list (background), but if user1 switch's to video call, it pops up a video call request(screen) on user2 device, and it works for multiple tries. How can i achieve this behavior? My activity gets called automatically for the first time, but when user puts my activity in background, it does not get called the second time.
Upvotes: 0
Views: 50
Reputation: 93688
Because you're in the background. There's restrictions on that now. See https://developer.android.com/guide/components/activities/background-starts for the limitations of what you can do in the background and when regarding launching Activities.
Upvotes: 0