Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android:IntentService启动但OnHandleContent未执行_Android_Android Intentservice - Fatal编程技术网

Android:IntentService启动但OnHandleContent未执行

Android:IntentService启动但OnHandleContent未执行,android,android-intentservice,Android,Android Intentservice,我想要一个IntentService每10秒运行一次,并放置一个简单的调试行。这是我的代码: 在舱单中: <service android:name="com.test.test.TheService" /> 服务本身 public class TheService extends IntentService { public static int SERVICE_ID = 1; public TheService() { super("TheS

我想要一个IntentService每10秒运行一次,并放置一个简单的调试行。这是我的代码:

在舱单中:

<service android:name="com.test.test.TheService" />
服务本身

public class TheService extends IntentService {

    public static int SERVICE_ID = 1;

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

    @Override
    protected void onHandleIntent(Intent intent) {
        Log.d("service","I'm in on Handle Intent");
    }
}
在模拟器的监视器中,我每10秒看到一行

am.setRepeating(AlarmManager.RTC_WAKEUP,
                    cal.getTimeInMillis(),
                    10000,
                    servicePendingIntent);
1270-1297/system_process I/ActivityManager: START u0 {flg=0x4 cmp=com.test.test/.TheService (has extras)} from pid -1
尽管它写的是“有额外的东西”,我实际上没有添加任何额外的东西。一般来说,这看起来不错,但调试从未打印,调试代码上的断点从未停止,就好像服务每隔10秒启动一次,但它什么也不做


我缺少什么?

您必须创建一个
意图
来调用您的
服务
,并使用方法
getService()
将其放入
pendingent
,如下所示:

Intent serviceIntent = new Intent(context, TheService.class);
PendingIntent pendingIntent = PendingIntent.getService(this,0, intent, 0);

您的logcat输出是否已过滤?如果未筛选,是否可以尝试添加断点并运行调试程序。它在调试模式下运行,但它从未在这一行Log.d(“服务”、“我在处理意图中”)的断点处停止;您是否正在使用
pedinginent.getService
生成挂起的意图?当我这样做时,整个过程被卡住了,然后我将其更改为PendingEvent ServicePendingEvent=PendingEvent.getActivity(上下文…,它开始工作了,只是它没有进入把手内部。你说它卡住了是什么意思?你应该使用getService()方法我从卡住应用程序的getService开始。我将其更改为getActivity,它出现了我上面描述的症状。在上面的一条评论说明了与此答案相同的内容后,我将其更改回getService,它开始出现问题work@Amos,酷,如果ti有用,请接受