为什么我的服务活动的OnDestroy这是由该服务启动后启动 [英] why my service starts after ondestroy of activity which was started by this service
本文介绍了为什么我的服务活动的OnDestroy这是由该服务启动后启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
今天,我发现了奇怪的problem.In我的申请,我开始从服务中的活动
意图=新的意图(AlarmService.this,GuardActivity.class);
in.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(在);
现在有时后我打电话的OnDestroy活动。在这里,我看到了我的服务将再次启动。 这种行为是非常strange.Do任何机构面临着同样的问题。
这是简单的服务,略高于行......所以,我不张贴完整的code
活动
TIMER T =新的Timer();
t.schedule(新的TimerTask(){
@覆盖
公共无效的run(){
尝试{
完成(); //活动10秒后自我毁灭
}
赶上(例外五)
{
}
}
},10 * 1000); // 10秒
解决方案
我张贴的答案,因为我不能评论,
已通过调用采空服务 stopself();
后
意图=新的意图(AlarmService.this,GuardActivity.class);
in.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(在);
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
解决方案
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);
这篇关于为什么我的服务活动的OnDestroy这是由该服务启动后启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文