Service的onStartCommand方法的疑问
来源:互联网 发布:js冒泡排序 从小到大 编辑:程序博客网 时间:2024/04/30 23:04
在Mars的Android视频的25集Service中,继承了Service类。依视频写代码,却发现没有public int onStartCommand (Intent intent, 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啊。
0 0
- Service的onStartCommand方法的疑问
- Service的onStartCommand方法的疑问
- Service的onStartCommand方法的疑问
- service的onStartCommand方法
- Service的onStartCommand方法空指针错误
- Service 中onStartCommand方法参数的含义
- Service里面的onStartCommand()方法详解
- Service的onStartCommand()方法返回值详解
- service的onstartcommand函数
- Service的onstartcommand
- service的onStartCommand
- service的onStartCommand走两遍
- Android Service生命周期 Service里面的onStartCommand()方法详解
- Android Service生命周期 Service里面的onStartCommand()方法详解
- Android Service生命周期 Service里面的onStartCommand()方法详解
- Android Service生命周期 Service里面的onStartCommand()方法详解
- service里面的onstart()方法和onStartCommand()方法的区别
- Service中onStartCommand回调方法的返回值分析
- 一个老程序员对学弟学妹的一些忠告
- validate.js的使用
- UP-CUP6410开发板烧写遇到的问题和解决方法
- java http 请求get 和post
- 世界杯的资深球迷
- Service的onStartCommand方法的疑问
- 数组平衡点问题
- aio,epoll,libevent,boost::asio解决的问题
- 走进博客的世界
- quartz2.2.1 example 09代码分析
- Web 3.0时代:网络对你无所不知
- 两种排序
- 图解正向代理、反向代理、透明代理
- UVa101-我的第一道uva