How to push app in background and launch from same screen in Appium with selenium Press home button from some specific screen. Put app in background. Open the app from same screen after some time interval

Hi,
I need to set the Native app in background and than get the same app in foreground with same opened page which I have last visited.

Here I am able to set the app in background by below code but not finding the way to get the app in foreground with last visited page, currently with below code approaches, the app is getting relaunched with initial login screen. Can any one please help in same.

Code1:

  1. driver.runAppInBackground(Duration.ofSeconds(15));
    2.Activity activity = new Activity(“com.gisteam.rjiomaps.projectresq”, “com.gisteam.rjiomaps.projectresq.main.MapFragmentActivity”);//activity name is as per the last visited page
    3.activity.setStopApp(false);
  2. ((AndroidDriver) driver).startActivity(activity);

Code2

  1. driver.runAppInBackground(Duration.ofSeconds(15));
    2.((AndroidDriver) driver).currentActivity();

Command runAppInBackground should send you app in background and restore to foreground on same screen (which mean same activity). Does not work same for you?

It is not working, as by using runAppInBackground the app goes in background and get closed.

Pls share appium logs at gist.github.com