Question

I wonder if I can run more than one application from a click within my application, I mean we have a few apps on our company, for one process the user needs to add information into from 2 different applications. I wonder if is possible to create a shortcut to start those 2 applications as a separate application?

I mean each one have the flag "Intent.FLAG_ACTIVITY_NEW_TASK"

lets assign some "nicknames" opener = Application that Im using. Where I want to add the shortcut to open the 2 applications i1 = application 1 i2 = application 2

A sample code that I use is:

Intent i1 = getAppIntent(someValueToGetTheIntent);
if (i1 != null){
    i1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    i1.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    startActivity(i1);
}

Intent i2 = getAppIntent(someOtherValueToGetTheIntent);
if (i2 != null){
    i2.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    i2.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    startActivity(i2);
}

When I do this the i2 application (Intent) is on the top. if I try to navigate to the i1 (in the open application menu) to switch to the other application, it doesnt exist, I can see the opener and i2 but NOT i1. If I click on the back button, then the i1 is started and then I do see all of them. but I want them to be there from the beginning.

The reason why i need the 3 open and allow the user navigate between them is because the 3 contain different information that are required to interact with the applications. eje opener have a form to be filled with the school and students information, i1 have school information, i2 have students information.

I know that the best approach would be consolidating the apps but is not possible at this moment so this would be a great help for the users.

So I want to know how to start more than one application as new task so they both apps be on the applications menu and the user can switch between them.

EDIT

I notice the method startActivities that gets an Intent array an fires all the applications, this is kind of what I need but still. It mentions: "will be created when the user first visits them (due to pressing back from the activity on top)." I wonder if that back button behavior can be avoided.

So I can "create" them before the user have to press the back.

Was it helpful?

Solution 3

Thanks everyone for your help, I know that the best approach is just use the startActivities that android have incorporated, and let the user know that needs to use the back button to navigate between activities. This is not an option for me at this moment.

I end up using a timer like this:

lunchAppTimer.removeCallbacks(runnable);
lunchAppTimer.postDelayed(runnable, 2000);
Handler lunchAppTimer = new Handler();
private Runnable runnable = new Runnable() {
    @Override
    public void run() {
        new LaunchApplication(mLIntent).execute();
    }
};

in LaunchApplication I have my startActivity this is iterated thru all the activities that I need at any given moment.

Again this may not be the best approach but in the search I did, I couldnt find a better solution to have 2 or more application running.

OTHER TIPS

Yes you can and I would suggest running them on asynchronous thread as well. Here is the jar for the ksoap2 library which I use to run async tasks in my android app.

https://code.google.com/p/ksoap2-android/source/browse/m2-repo/com/google/code/ksoap2-android/ksoap2-android-assembly/#ksoap2-android-assembly%2F2.5.5

Lmk if you need anymore help.

Android only allows one activity to be active at a time. When a new activity is started, the current activity is saved to the "activity stack" for later use. The system eventually cleans up the activity stack if the garbage collector determines it is safe to do so.

The correct way to do what you are trying to do is to create a custom intent for your applications to be passed between them. This is the Android way of passing data between unrelated applications, and is the correct way to handle your problem.

If you are talking about two activities, and not two applications, you can use startActivityForResult(). This allows you to return results from an activity, rather than passing it explicitly around in the intent. This can be better, as you don't always have to serialize it yourself this way.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top