Java 启动Android服务

Java 启动Android服务,java,android,android-intent,background-service,Java,Android,Android Intent,Background Service,抱歉,如果这是一个愚蠢的问题,但如何启动android服务?我无法找出公共类scilentservice extends IntentService{上的错误代码(请参见下面的代码)。我认为这可能与意图有关,但我不确定。我希望我的应用程序启动该服务,然后在特定时间自动启动手机。 这是我的密码 /** * Created by Abe on 3/29/2015. */ import android.app.IntentService; import android.content.Inten

抱歉,如果这是一个愚蠢的问题,但如何启动android服务?我无法找出
公共类scilentservice extends IntentService{
上的错误代码(请参见下面的代码)。我认为这可能与意图有关,但我不确定。我希望我的应用程序启动该服务,然后在特定时间自动启动手机。 这是我的密码

/**
 * Created by Abe on 3/29/2015.
 */

import android.app.IntentService;
import android.content.Intent;

public class scilentservice extends IntentService {
    @Override
    protected void onHandleIntent(Intent workIntent) {
        // Gets data from the incoming Intent
        String dataString = workIntent.getDataString();
        ...
        // Do work here, based on the contents of dataString
        ...
    }
}
`

提前感谢您的帮助。

我使用了
扩展意图
并覆盖方法
onstart命令

@Override
public int onStartCommand(Intent intent, int flags, int startId) {


    return 1;
}

您可以通过某个活动发送的某个命令或发送给应用程序的某个通知启动服务。

此问题将被否决,可能会被关闭,因为这是一个简单的问题。请查看注释中链接的文档,然后查看如何发送请求…这是Android文件

片段:

为名为RSSPullService的IntentService创建新的显式意图

/*
 * Creates a new Intent to start the RSSPullService
 * IntentService. Passes a URI in the
 * Intent's "data" field.
 */
mServiceIntent = new Intent(getActivity(), RSSPullService.class);
mServiceIntent.setData(Uri.parse(dataUrl));
调用startService()

intentService代码:

public class RSSPullService extends IntentService {

    public RSSPullService() {
        super("RSSPullService");
    }

    @Override
    protected void onHandleIntent(Intent intent) {
        //Do the work here.
    }
}

“Auto science在特定时间启动手机”?“我无法找出错误代码”什么错误代码?那不是同一件事。IntentService不应该重写onStartCommand,因为它会被基类调用。@MartínMarconcini这就是为什么我说我使用了一个服务,它工作了,更糟糕的是,因为
服务
IntentService
不是同一件事。如果你使用了一个服务,你会必须重写onStartCommand。但就我从他的问题中所能理解的而言,用户并没有要求使用服务。@MartínMarconcini问题是如何启动android服务,并认为这可能会有所帮助。你是对的。我认为这是“用户没有线索”的情况.无论如何,没有提供进一步的信息,所以我怀疑这里还有很多事情要做。
public class RSSPullService extends IntentService {

    public RSSPullService() {
        super("RSSPullService");
    }

    @Override
    protected void onHandleIntent(Intent intent) {
        //Do the work here.
    }
}