-1

我有一个名为 ForegroundService 的服务类,在 onstartCommand 中我需要设置一个变量:

@Override
   public int onStartCommand(Intent intent, int flags, int startId) {
     VariableManaging.isStop=false; //<==variable i need to set. Here i got an exceptioninInitializer error when my bootReceiver start service on startup. If service is start by button on activity got no error. 
   }

变量管理类开始于:

static boolean isStop=true;
static ProgressDialog progressDialog=new ProgressDialog(Main.activity); //<== I noted that if i remove this all working well

有办法设置该变量吗?

4

1 回答 1

0

Your code is correct but the method onStartCommand() will NOT be called unless you start this service like this:

startService(new Intent(getApplicationContext(), ForegroundService.class));
于 2013-01-20T01:59:48.183 回答