0
  val intent = Intent(Intent.ACTION_MAIN)
        .addCategory(Intent.CATEGORY_HOME)
        .setClassName( "com.example.AnotherPhoneTabletModule","com.example.AnotherPhoneTabletModule.MainActivity")
        .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
        .addFlags(Intent.FLAG_FROM_BACKGROUND)
        .setComponent(ComponentName("com.example.AnotherPhoneTabletModule", "com.example.AnotherPhoneTabletModule.MainActivity"))

    applicationContext.startActivity(intent)[1]

There are two phone/tablet modules and want to do start activity in another module. However, from the reason of setting flag or category the other module is creating different application. Is it possible in same application to start another activity from another phone/tablet module without using android library module.

Two different apps

  • You should remove flag addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) .addFlags(Intent.FLAG_FROM_BACKGROUND) and start by activity context – Công Hải Jun 09 '20 at 10:53
  • It returns "Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want? at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3270)" this error not worked unfortunately @Công Hải – Cihat Bostanci Jun 09 '20 at 11:05
  • No dont use application context to start. Did you try start by activity? – Công Hải Jun 09 '20 at 11:09

1 Answers1

0
val intent = Intent(Intent.ACTION_MAIN)
            .addCategory(Intent.CATEGORY_HOME).setClassName("com.example.AnotherPhoneTabletModule","com.example.AnotherPhoneTabletModule.MainActivity")
            .setComponent(ComponentName("com.example.AnotherPhoneTabletModule", "com.example.AnotherPhoneTabletModule.MainActivity"))

        startActivity(intent)

This code worked for me.