查询我的服务何时在Android中运行?

时间:2015-04-23 02:17:36

标签: android service receiver

我有一个服务,每隔5分钟就会启动一次...我如何查询android以查看此服务何时以编程方式启动?

    <!-- Send Census Service -->
    <service android:name="services.scheduled.SendCensusScheduledService"
             android:icon="@drawable/ic_launcher"
             android:label="SyncServerDataScheduledService" />
    <receiver android:name="services.receivers.SendCensusScheduledServiceReceiver" >
        <intent-filter>
            <action android:name="ReceiptBucketClient.android.action.broadcast"/>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
        </intent-filter>
    </receiver>
    <receiver android:name="services.receivers.StartSendCensusScheduledServiceReceiver" />

1 个答案:

答案 0 :(得分:0)

通过PendingIntent检查:

PendingIntent intent = PendingIntent.getBroadcast(context, 0, 
        new Intent("ReceiptBucketClient.android.action.broadcast"), 
        PendingIntent.FLAG_NO_CREATE;

if (intent != null) {
   // you have the service scheduled. Cancel it!
   intent.cancel();
}

请记住only the original application owning a PendingIntent can cancel it.