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..
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With