0

I have two apps, A and B.
I want to call B by A.
My code in A is as below:

Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(new ComponentName("com.example.bapp","com.example.bapp.BActivity"));
intent.putExtra ("test2abc", "abctest2");
startActivity(intent);

And B's intent filter in manifest as below:

<intent-filter>
    <action android:name="ACTION_BACKCALL" />
    <category android:name="android.intent.category.DEFAULT" />
</intent-filter>

But it will close B before launch B while B had opened.
I find below code to open *.txt file. This will open two txt reader app at the same time.

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), mimetype);
startActivity(inte

nt);

How can I arrive that?

rags
  • 2,570
  • 15
  • 37
brian
  • 6,584
  • 28
  • 80
  • 122

2 Answers2

4

hey i found this code snippet Launch an application from another application on Android which will work for you set the address of the application which you want to launch

Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("com.package.address");
startActivity(LaunchIntent);
Community
  • 1
  • 1
Swapnil
  • 3,581
  • 4
  • 26
  • 32
2

you might want to try android:launchMode="singleInstance" and android:finishOnTaskLaunch="true" while defining launcher activity.

   <activity
        android:name="com.example.test.sampleMediaPlayer"
        android:label="@string/app_name"
        android:launchMode="singleInstance"
        android:finishOnTaskLaunch="true" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

For Activity A.

Nimish Choudhary
  • 1,998
  • 16
  • 17