在服务的onStartCommand中返回什么 [英] what to return in onStartCommand for a service

查看:62
本文介绍了在服务的onStartCommand中返回什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在浏览文档,有时 onStartCommand()返回 START_NOT_STICKY ,有时返回以下内容:

I have been looking through the documentation and sometimes the onStartCommand() returns START_NOT_STICKY, sometimes it returns the following:

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    // TODO Auto-generated method stub
    return super.onStartCommand(intent, flags, startId);
}

对于某些服务为什么返回 super.onStartCommand(intent,flags,startId);

I am now confused as to why some services return super.onStartCommand(intent, flags, startId);

推荐答案

这一切都取决于您想要的内容.文档说:

It all depends on what you want. The documentation says:

为了向后兼容,默认实现调用onStart(Intent,int)并返回START_STICKY或START_STICKY_COMPATIBILITY.

For backwards compatibility, the default implementation calls onStart(Intent, int) and returns either START_STICKY or START_STICKY_COMPATIBILITY.

因此,返回 super.onStartCommand()等同于返回 START_STICKY .如果您不想使用默认行为,则可以返回另一个常量.

So returning super.onStartCommand() is equivalent to returning START_STICKY. If you don't want the default behavior you can return another constant.

这篇关于在服务的onStartCommand中返回什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆