문제

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