Switching between apps without relauncing


#1

I an trying to switch between the chrome browser and a hybrid app .Is there is any way to switch between the apps without relaunching it. I have gone through some blogs and support pages but saw that the apps will be relaunched when calling driver.startActivity().So i need some workaround where the apps will bot get relaunched. Please let me know if there is any other method that can be used.


#2

do you ask for android or iOS ?


#3

If it’s for Android try using adb commands:

Call this method twice and you will be able to switch between apps
public static void switchApp(){
runCommand(“adb shell input keyevent KEYCODE_APP_SWITCH”);
}

here is the runCommand:
public static String runCommand(String command){
String output = null;
try{
Scanner scanner = new Scanner(Runtime.getRuntime().exec(command).getInputStream()).useDelimiter("\A");
if(scanner.hasNext()) output = scanner.next();
}catch (IOException e){
throw new RuntimeException(e.getMessage());
}
return output;
}


#4

you can use activateApp API


#5

I am asking for both android and iOS @Bilal_Jarwan


#6

okay thank you @chouaib_saadi will try this


#7

okay @mykola-mokhnach Will try this aswell


#8

this article for iOS.