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

3
  • You should remove flag addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) .addFlags(Intent.FLAG_FROM_BACKGROUND) and start by activity context Commented Jun 9, 2020 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 Commented Jun 9, 2020 at 11:05
  • No dont use application context to start. Did you try start by activity? Commented Jun 9, 2020 at 11:09

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.