Java – How to run a separate application with a single click from an Android button

How to run a separate application with a single click from an Android button… here is a solution to the problem.

How to run a separate application with a single click from an Android button

I tried adding two buttons to my Android app to select one app from two separate app order system and inventory system. As shown in the image.

enter image description here

I’ve implemented these two apps as separate two Android projects. When I try to run this application, it goes to the selection window correctly, but when a button is pressed, the emulator displays a “force close” message.
I’ve added the Order System and Inventory System items to the build path for the first application and then imported their packages (com.oms.ws and com.inv.ws). This may not be true, but don’t know how to do it. Please help me! I’m new to Android.
I want to test this app using the emulator!

This is the code I used to select the application.

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import com.oms.ws.*;

public class ThirdScreen extends Activity {

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.thirdscreen);

Button oms;
    oms = (Button)findViewById(R.id.orderSystem); 
    oms.setOnClickListener(ordrMnagemntSys);

Button inventory;
    inventory = (Button)findViewById(R.id.inventorySystem); 
    inventory.setOnClickListener(inventorySys);

}

private OnClickListener ordrMnagemntSys = new OnClickListener(){
    public void onClick(View v) {

Intent oMs = new Intent(getApplicationContext(), com.oms.ws.TestOms.class);
            startActivity(oMs);
            }
};

private OnClickListener inventorySys = new OnClickListener(){
    public void onClick(View v) {

Intent inven = new Intent(getApplicationContext(), com.inv.ws.TestInventory.class);
            startActivity(inven);
            }
};
}

Thanks!

Solution

Okay, this works

Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("org.abc");
startActivity(LaunchIntent);

Replace org.abc with the package name of the application you want to launch.

Related Problems and Solutions