为什么我的服务在此服务启动的活动开始之后启动

时间:2014-03-29 11:38:59

标签: android android-intent service android-activity

今天我发现了一个奇怪的问题。在我的申请中,我正在从服务

开始一项活动
Intent in=new Intent(AlarmService.this, GuardActivity.class);
in.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  startActivity(in);

现在有一段时间我打电话给活动。在这里,我观察到我的服务再次启动。 这种行为很奇怪。任何身体都面临同样的问题

这是简单的服务,就在上面......所以我没有发布完整的代码

活动

       Timer t = new Timer();
       t.schedule(new TimerTask() {

              @Override
              public void run() {

                     try{
                         finish();//Activity destroy itself after 10 sec
                     }
                     catch(Exception e)
                     {

                     }
                   }
       }, 10*1000);// 10 sec

1 个答案:

答案 0 :(得分:1)

我发帖回答因为我无法发表评论, 你有没有通过拨打stopself();来停止服务 之后

Intent in=new Intent(AlarmService.this, GuardActivity.class);
in.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(in);