3

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?

JRG
  • 3,677
  • 3
  • 17
  • 32
the_prole
  • 6,481
  • 11
  • 56
  • 120
  • background means? – Pratik Popat Aug 02 '17 at 04:48
  • Not really sure. I guess apps running in the back ground are really just using services. – the_prole Aug 02 '17 at 04:51
  • you basically need to start service on boot completed action. – LostGeek Aug 02 '17 at 05:02
  • I don't want to run my own app in the background, I want to run another app in the back gourd, which means I need to start up its background service on boot up. – the_prole Aug 02 '17 at 05:04
  • For this requirement, I guess you have to go for broadcast receivers and I guess that's the only way to communicate between two apps with a tag android:exported="true". Whether or not the broadcast receiver can receive messages from sources outside its application — "true" if it can, and "false" if not. If "false". – Androwed Aug 02 '17 at 05:23

3 Answers3

1

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.

Androwed
  • 413
  • 5
  • 10
  • 1
    I want to start up background service of another app. It is possible? – the_prole Aug 02 '17 at 05:08
  • https://stackoverflow.com/questions/3872063/launch-an-application-from-another-application-on-android see this, but it is regarding launching activity but not sure for a service. – Androwed Aug 02 '17 at 05:13
  • For this requirement, I guess you have to go for broadcast receivers and I guess that's the only way to communicate between two apps with a tag android:exported="true". Whether or not the broadcast receiver can receive messages from sources outside its application — "true" if it can, and "false" if not. If "false". – Androwed Aug 02 '17 at 05:20
0

try this

public class Background extends Service { 
//declare variables
@Nullable
@Override
public IBinder onBind(Intent intent) {
    return null;
}


@Override
public int onStartCommand(Intent intent, int flags, int startId) {

    //your code here


    return 1;
}
Murari
  • 378
  • 1
  • 12
  • No I want to start up another apps background service, but I don't think that's possible. – the_prole Aug 02 '17 at 04:59
  • i am not really sure about this but in my opinion that app can only start its own service. please try if broadcast intents solves your problem... – Murari Aug 02 '17 at 05:04
0

I think you can start it, but you can use it

As mentioned in this android service exported attribute?

The purpose of the "exported" is to let other apps have access to a service.

The above post explained it very well. May it will be helpful for others too.

Rahul Khurana
  • 7,582
  • 5
  • 29
  • 54