Reputation: 21
I want to run 3 apps at the same time and launch them from another app.
One way:
startActivity(getPackageManager().getLaunchIntentForPackage("x.x.x0"));
startActivity(getPackageManager().getLaunchIntentForPackage("x.x.x1"));
startActivity(getPackageManager().getLaunchIntentForPackage("x.x.x2"));
Apps work one after another.
Another way:
new Thread() {
@Override
public void run() {
startActivity(getPackageManager().getLaunchIntentForPackage("x.x.x0"));
}
}.start();
new Thread() {
@Override
public void run() {
startActivity(getPackageManager().getLaunchIntentForPackage("x.x.x1"));
}
}.start();
new Thread() {
@Override
public void run() {
startActivity(getPackageManager().getLaunchIntentForPackage("x.x.x2"));
}
}.start();
Only the last app works.
What am I doing wrong?
Upvotes: 0
Views: 74
Reputation: 1250
If you want to launch several activities at once, so there is rarely used option of startActivities instead of calling multiple startActivity
.
The documentation of this method also describes why your option of calling startActivity 3 times doesn't work:
This is generally the same as calling startActivity(android.content.Intent) for the first Intent in the array, that activity during its creation calling startActivity(android.content.Intent) for the second entry, etc.
Android expects to launch only one activity by startActivity. The second one should be only launched from onCreate of the first one. If you expect all 3 activity to be launched simultaneously, then probably this note is also important for your:
Note that unlike that approach, generally none of the activities except the last in the array will be created at this point, but rather will be created when the user first visits them (due to pressing back from the activity on top).
Upvotes: 2