Service的onStartCommand方法的疑问
2011-08-09 17:51
267 查看
在Mars的Android视频的25集Service中,继承了Service类。依视频写代码,却发现没有public int onStartCommand (Intent intent,
int flags, int startId)可以覆写。查了一下API文档,在示例代码的onStart方法注释之中有这样两句话:
看到这里才恍然大悟,原来onStart方法是在Android2.0之前的平台使用的.在2.0及其之后,则需重写onStartCommand方法,同时,旧的onStart方法则不会再被直接调用(外部调用onStartCommand,而onStartCommand里会再调用 onStart。在2.0之后,推荐覆盖onStartCommand方法,而为了向前兼容,在onStartCommand依然会调用onStart方法。感谢 swordlife1986的指正)。
在文档中,onStart方法的解释是以下两句话:
意思就是不赞成使该方法。该方法的实现已经被onStartCommand所代替。
看来还是以前的惯性思维啊。之前建工程的时候一直都是选以1.6为最低的平台,这次也选了这个,难怪会在重写的时候没有这个方法了。另外,看到视频后面,在AndroidManifest.xml中果然看到了这样一句:
最低平台为7,貌似就是Android2.1啊。
int flags, int startId)可以覆写。查了一下API文档,在示例代码的onStart方法注释之中有这样两句话:
// This is the old onStart method that will be called on the pre-2.0 // platform. On 2.0 or later we override onStartCommand() so this // method will not be called.
看到这里才恍然大悟,原来onStart方法是在Android2.0之前的平台使用的.在2.0及其之后,则需重写onStartCommand方法,同时,旧的onStart方法则不会再被直接调用(外部调用onStartCommand,而onStartCommand里会再调用 onStart。在2.0之后,推荐覆盖onStartCommand方法,而为了向前兼容,在onStartCommand依然会调用onStart方法。感谢 swordlife1986的指正)。
在文档中,onStart方法的解释是以下两句话:
This method is deprecated. Implement onStartCommand(Intent, int, int) instead.
意思就是不赞成使该方法。该方法的实现已经被onStartCommand所代替。
看来还是以前的惯性思维啊。之前建工程的时候一直都是选以1.6为最低的平台,这次也选了这个,难怪会在重写的时候没有这个方法了。另外,看到视频后面,在AndroidManifest.xml中果然看到了这样一句:
<use-sdk android:minSdkVersion="7" />
最低平台为7,貌似就是Android2.1啊。
相关文章推荐
- Service的onStartCommand方法的疑问
- Service的onStartCommand方法的疑问
- service里面的onstart()方法和onStartCommand()方法的区别
- Android--service里 onstart()onStartCommand()方法的区别
- service的onStartCommand方法
- 我的Android进阶之旅------>android中service的onStartCommand()方法中intent为null的问题
- Android中service的onStartCommand()方法中intent为null的问题
- Android中 Service的onStartCommand方法空指针错误
- Service中onStartCommand方法intent报空的问题
- Android Service生命周期 Service里面的onStartCommand()方法详解
- Android Service的onStartCommand方法返回值作用
- Android Service生命周期 Service里面的onStartCommand()方法详解
- Service中的onStartCommand()方法的三种返回值的含义以及理解
- Android Service生命周期 Service里面的onStartCommand()方法详解
- Android Service生命周期 Service里面的onStartCommand()方法详解
- Service之onStartCommand()方法解析笔记
- Android Service生命周期 Service里面的onStartCommand()方法详解
- service中onStartCommand方法return介绍和如何创建不被杀死的service
- Android Service的理论探讨与实践(二)之onStartCommand()方法返回值的探究
- Service中onStartCommand回调方法的返回值分析