Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Start Application At boot time

I want to start my app at boot time, but want activity run in background at that time...

I have implemented BroadcastReceiver class for this, which is:

public class StartMyServiceAtBootReceiver extends BroadcastReceiver {

 @Override
 public void onReceive(Context context, Intent intent) {
    // TODO Auto-generated method stub
    Intent myIntent = new Intent(context, MainActivity.class);
    myIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(myIntent);

   }
}

but activity comes to front..

like image 727
Naveed Ali Avatar asked Aug 21 '26 09:08

Naveed Ali


2 Answers

For what you want the achieve... Activity can't be run in background, as it will start and will be visible to the user.

What you may do is... Start a service at boot time which after few seconds starts your activity or whenever you want.

like image 196
Rachit Mishra Avatar answered Aug 26 '26 02:08

Rachit Mishra


For background tasks we use services on android.This way you can have your app performing your operations in the background with out bringing the app to foreground.

like image 33
Madala Avatar answered Aug 26 '26 04:08

Madala



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!