Search code examples
androidbackground-process

How to launch another app in the background?


I'm launching my app on boot up but I want it to start up in the background.

Intent launchIntent = context.getPackageManager().getLaunchIntentForPackage("my.app");
if (launchIntent != null) {
   context.startActivity(launchIntent);//null pointer check in case package name was not found
}

Any idea how to do that without the app start up in the foreground?


Solution

  • Theoretically an app majorly consists of two components.

    1. Activity : Runs in foreground which is mainly a GUI for an app and user interacts with activity as it take inputs from user and displays required results.

    2. Service: Runs in background which does all the operations required by activity to produce results by receiving the inputs from activity(user) and send back the results to activity for displaying them.

    So, your question of starting an app in background ! This can be achieved by starting a service of your app on boot up and carry out tasks which you want to perform.

    P.s : To start a Service on boot-up, you will require to set up a Boot-Receiver. If you want any further information regarding this, please let me know.