Вопрос

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

Это было полезно?

Решение 2

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.

Другие советы

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.

If you want something to run in the background you'll have to create a service, from which you can then start your main acrivity at a certain time

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top