1

I have two apps, the app 'A' and app 'B' and the first app it's composed of one activity (1) and the second app have two activities (1, 2).

The thing it's that I need to call from A1 to B2 without having B1 appearing. But when I call it, always shows first the B1 and then passes automatically to B2 and when I push back on B2 I need to get back to A1, but it returns to B1.

This is my code when calling the intent:

val intent = Intent()
intent.component = ComponentName("com.app.appB", "com.app.appB.route.to.activity2")
intent.putExtra("stuff", someStuff)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK

And this is the activity2 from B on its manifest:

<activity
    android:name=".route.to.activity2"
    android:screenOrientation="portrait"
    android:exported="true">
</activity>

I've tried to change the flags but whey I do I get this error:

android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity  context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?

Also I've tried adding noHistory = true to the manifest but doesn't change anything.

I hope someone can help soon, thanks!

EDIT 1

Also tried to use an intent-filter like said in this post: Launch Activity from another Application Android but still not working, the behaviour remains the same.

Added this to the activity in the manifest:

<intent-filter>
      <action android:name="com.app.appB.route.to.activity2.LAUNCH_IT"/>
      <category android:name="android.intent.category.DEFAULT"/>
</intent-filter>

and called the activity this way:

val intent = Intent()
intent.action = "com.app.appB.route.to.activity2.LAUNCH_IT"
intent.putExtra("stuff", someStuff)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
applicationContext.startActivity(intent)
Óscar
  • 51
  • 1
  • 11

1 Answers1

0

After a lot of research and tries, I've found that adding the next parameter to the activity in the manifest works like a charm. I hope this can help someone else:

android:launchMode="singleInstance"
Óscar
  • 51
  • 1
  • 11