Error: 'Activity used to start app doesn't exist or cannot be launched! Make sure it exists and is a launch-able activity' is appearing


#1

Error: ‘Activity used to start app doesn’t exist or cannot be launched! Make sure it exists and is a launch-able activity’ is appearing.
Can you please provide me a solution for this type of error message, i am using below mentioned code:

i just want little favor if someone can provide source code for scenario in which app is switching between different activities within the app.

Also just want to confirm that do i need to create individual capabilities for each activity like in code mentioned by me in below code.

public class Capabilities {
AndroidDriver andDriver;
private String appPackage = “com.abc.xyz.xyz”;
//private String appPackageAcivity = “com.abc.xyz.xyz.Activity”;

private String splashActivity = “com.abc.xyz.xyz.Activity.SplaseActivity”;
private String loginActivity = “com.abc.xyz.xyz.Activity.LoginActivity”;
private String mainActivity = “com.abc.xyz.xyz.Activity.MainActivity”;

public AndroidDriver getAndDriver() {
return andDriver;
}

public void setAndDriver(AndroidDriver andDriver) {
this.andDriver = andDriver;
}

public Capabilities() {

createCapabilites(loginActivity);
}

public AndroidDriver createCapabilites(String activityName) {
File Build = new File(“src”);
File TestBuild = new File(Build, “xyz.apk”);

DesiredCapabilities capabilities = DesiredCapabilities.android();
capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, “Appium”);
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, “Android”);
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, “Emulator_Nexus6”);
capabilities.setCapability(MobileCapabilityType.NO_RESET, true);
capabilities.setCapability(MobileCapabilityType.FULL_RESET, false);

capabilities.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, appPackage);
capabilities.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, splashActivity);
capabilities.setCapability(“autoGrantPermissions”, true);
capabilities.setCapability(MobileCapabilityType.APP, TestBuild.getAbsolutePath());

try {
andDriver = new AndroidDriver(new URL(“http://127.0.0.1:4723/wd/hub”), capabilities);
andDriver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
return andDriver;

}

public void navigateToMainScreen() {

File Build = new File(“src”);
File TestBuild = new File(Build, “xyz.apk”);

DesiredCapabilities capabilities = DesiredCapabilities.android();
capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, “Appium”);
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, “Android”);
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, “Emulator_Nexus6”);
capabilities.setCapability(MobileCapabilityType.NO_RESET, true);
capabilities.setCapability(MobileCapabilityType.FULL_RESET, false);

capabilities.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, appPackage);
capabilities.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, mainActivity);
capabilities.setCapability(“autoGrantPermissions”, true);
capabilities.setCapability(MobileCapabilityType.APP, TestBuild.getAbsolutePath());

try {
andDriver = new AndroidDriver(new URL(“http://127.0.0.1:4723/wd/hub”), capabilities);
andDriver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
}


#2

@abhiqa you can not just start any activity of your app if your app does not allow this -:slight_smile:

if you trying just start your app and just need some activity mention to wait - give it in another way like:

capabilities.setCapability(AndroidMobileCapabilityType.APP_WAIT_ACTIVITY, "com.sdei.*");

#3

@Aleksei thanks for your reply. i tried your code but it’s not working.
let me explain you the scenario.
In my case i need to switch b/w two different activities of same app.
first i just setup capabilities using the capabilities and than extends it to login class.
in login class first i need to click on an element on landing screen which open option to switch to login screen, now i pass username and password and complete the login process and navigated to next screen which contain other activity ‘main activity’.
now when i tried to perform another scenario in which i need to click on some element of ‘main activity’ screen.
i just again perform login process and tried to tap on that element on ‘main activity’ screen. it shown me error that element doesn’t exist.
when i consult with my developer he told me that you are displayed a main activity screen but your activity is yet not switched to main activity.
i tried to switch to main activity using below mentioned code:

public void startActivity()
{
String appPackage = “com.abc.xyz.xyz”;
String mainActivity = “com.abc.xyz.xyz.Activity.MainActivity”;
System.out.println(“Setting new activity”);
Activity activity = new Activity(appPackage, mainActivity);
activity.setAppWaitPackage(appPackage);
addDelay();
addDelay();
activity.setAppWaitActivity(mainActivity);
addDelay();
activity.getAppActivity();
getAndDriver().startActivity(activity);
}

above method and some other methods are getting executed in another method of another class mentioned below:

public ScriptPerformActivity() {
super();
LandingScreen landing = new LandingScreen();
landing.addDelay();
landing.navigateToMainScreen();
landing.startActivity();
landing.addDelay();
landing.clickOnLogo();

}

but its not working for us.
it’ll be great if you can help.

there is one notable condition with app, like you need to login into application one time only. if you have logged-in once and app is available in device/emulator, when you launch the app, you’ll be directly navigated to main activity screen.

thanks in advance.


#4

@abhiqa double check in adb shell that you can start needed activity with:

am start -n yourpackagename/.activityname
// or 
adb shell am start -n com.example.demo/com.example.test.MainActivity

#5

Hi, as your suggestion, my command
adb shell am start -n mycompany.android/.activity.SplashActivity
can start and my app launched
And my capabilities:
capabilities.setCapability("appWaitPackage", "mycompany.android");
capabilities.setCapability("appWaitActivity", ".activity.SplashActivity");
but my code still show error log
Caused by: org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: Cannot start the 'mycompany.android' application. Visit https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/android/activity-startup.md for troubleshooting. Original error: Cannot start the 'mycompany.android' application. Visit https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/android/activity-startup.md for troubleshooting. Original error: Activity name '.com.squareup.leakcanary.internal.DisplayLeakActivity' used to start the app doesn't exist or cannot be launched! Make sure it exists and is a launchable activity
Hope you can help!