Search code examples
androidandroid-activityandroid-serviceandroid-background

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..


Solution

  • 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.