0

I have tried all the examples in SO and they do not work for me. I wish to start a specific class in another application (not main) from inside my application.

I can start the application main page with this code (this works but not the class I want):

    Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("com.paloaltophoto.starttimer");
    startActivity(LaunchIntent);

But when I follow the examples from other SO answers to try and get to the class I want, I get an error

public void onTest(View v){
        Intent intent = new Intent();
        intent.setComponent(new ComponentName("com.paloaltophoto.starttimer", "com.paloaltophoto.starttimer.edit"));
        startActivity(intent);
}

I get a message about com.paloaltophoto.starttimer/com.paloaltophoto.starttimer.edit not being declared in my manifest but the manifest has this code:

   <activity android:name="com.paloaltophoto.starttimer.edit">
   </activity> 

Everything complies fine. Obviously the other application allows me to launch it as I can start it just fine on the main page but I can't find any reference on how I should make this work for a specific class.

Allen Edwards
  • 1,488
  • 1
  • 27
  • 44

2 Answers2

0

The class is defined as:

ComponentName(package, activity_name)

So, from your comments, you need:

intent.setComponent(new ComponentName("com.paloaltophoto.startline", "com.paloaltophoto.starttimer.edit"));

because your package is name is different from your component path.

Jim
  • 10,172
  • 1
  • 27
  • 36
0

In order to run another activity from another application you should call:

try {
    Intent intent = new Intent();
    intent.setComponent(new ComponentName(requiredPackage, requiredClazz));
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intent);
} catch (ActivityNotFoundException ex) {
    ex.printStackTrace();
} catch (Exception ex) {
    ex.printStackTrace();
}

Above code can throw:

Community
  • 1
  • 1
piobab
  • 1,352
  • 2
  • 13
  • 21