【发布时间】:2011-10-17 20:45:41
【问题描述】:
根据我对应用程序生命周期(包括服务)的理解,它应该继续 onCreate > onStart > onResume。
基于这种理解,如果您在 onCreate 中使用 this.stopSelf() 关闭循环,则它永远不会触发 onStart。
@Override
public void onCreate()
{
super.onCreate();
Log.i(TAG, "Service starting");
this.stopSelf();
}
@Override
public void onStart(Intent intent, int startId)
{
super.onStart(intent, startId);
Log.i(TAG, "onStart Service");
}
我希望 onStart 日志不会触发。但是,LogCat 清楚地表明,尽管服务在 onCreate 中终止,但 onStart 仍然运行。
这是意料之中的吗?这是为什么呢?
【问题讨论】:
标签: android lifecycle oncreate onstart