why my service starts after ondestroy of activity which was started by this service

送分小仙女□ 提交于 2019-12-08 09:02:16

问题


Today I found the strange problem.In my application I am starting a activity from service

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

Now after sometime i call ondestroy of activity. here I observe that my service is started again. This behavior is very strange.Do any body faced same problem

It is simple services with just above line...So I am not posting complete code

Activity

       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:


I am posting on answer because of I can't comment, had you stoped service by calling stopself(); after

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


来源:https://stackoverflow.com/questions/22730597/why-my-service-starts-after-ondestroy-of-activity-which-was-started-by-this-serv

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!