2

I'm writing a basic application. One of the features I'm interested in trying to do is to launch another app, INSIDE the app already running.

Eg. I have an app with 3 menu options, 1 and 2 do certain tasks as part of this parent app, menu option 3 launches another app that's installed on the phone. I'm not sure if this is possible?

Yury
  • 19,498
  • 7
  • 52
  • 79
BobX
  • 21
  • 1
  • 2

1 Answers1

4

This is possible with the Intents mechanism.

The exact Intent you'll have to write depend on various factors:

  • do you have to provide some data to the launched application?
  • do you target a specific application or do you want to let the user choose the application he prefers for that task (in case he has several applications able to do what you need)?
  • do you want to ensure that the application is available? (that would be better)
  • do you know if the other app provides specific intent-filters to do some tasks?

Edit:

Then, you should be able to start the second application with the following code:

Intent i = new Intent(Intent.ACTION_MAIN);
i.addCategory(Intent.CATEGORY_LAUNCHER);
i.setPackage("com.otherapp.package");
startActivity(i);

Place this code in the OnClickListener of your button and that should be enough.

Kevin Gaudin
  • 9,647
  • 3
  • 29
  • 34
  • No data needs to be provided A specific app is the target, and only target, the app will be definately available, so not an issue at the moment. Im unusure of your last question? Thanks! – BobX Nov 01 '10 at 22:56
  • Thank you. Will test. :) EDIT: Where should I place the other app? is it ok if already installed on the phone, or must the source code be placed somewhere specific? – BobX Nov 01 '10 at 23:23
  • 1
    Well, first, you should read the developer guide fundamentals (http://d.android.com/guide/topics/fundamentals.html). The application must be installed on the phone and you have to know its package name (what I included in the sample "com.otherapp.package"). – Kevin Gaudin Nov 01 '10 at 23:33
  • Didn't actually work, It hung for a few seconds and gave an error. Hear is my code. Want to press menu item to launch "setup activity" which should boot into the astro file manager app. – BobX Nov 02 '10 at 20:10
  • public void onItemClick(AdapterView> parent, View itemClicked, int position, long id) { TextView textView = (TextView) itemClicked; String strText = textView.getText().toString(); if (strText.equalsIgnoreCase(getResources().getString(R.string.menu_item_setlaunch))) { // Launch the setup Activity startActivity(new Intent(FYPMenuActivity.this, FYPSetupActivity.class)); [[[here is where Kevins code goes, but package is set to astro's - com.metago.astro]]] – BobX Nov 02 '10 at 20:12
  • this code then follows Kevins snippet ----------------- } else if (strText.equalsIgnoreCase(getResources().getString(R.string.menu_item_scweb))) { // Launch the Scores Activity startActivity(new Intent(FYPMenuActivity.this, FYPScwebActivity.class)); } – BobX Nov 02 '10 at 20:14
  • Hi guys, I am still getting "Sorry! The application has stopped unexpectedly. Please try again." Trying to launch astro from inside a custom app when I click a menu item button. Heres my code. – BobX Nov 07 '10 at 15:46