我创建了无法启动服务的简单 IntentService 框架。我已经添加了调用、主代码块和清单条目,但我仍然没有得到任何日志输出。我在这里检查了其他类似的答案,但都指向我已将条目添加到的清单:
显现:
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:name=".ApplicationGlobal">
<service android:name=".MyIntentServiceImpl" />
启动服务:
Intent intent = new Intent(ThisActivity.this, MyIntentServiceImpl.class);
startService(intent);
服务代码:
public class MyIntentServiceImpl extends IntentService implements MyIntentService {
private boolean result;
private Long pollingCount;
public MyIntentServiceImpl (){
super("MyIntentServiceImpl ");
Log.d(TAG, "Creating Polling Service");
this.result = false;
this.pollingCount = 0L;
}
@Override
protected void onHandleIntent(Intent arg0) {
Log.d(TAG, "Polling Service Started");
while(!result && (pollingCount <= MAX_POLLING_VALUE)){
pollingCount++;
Log.d(TAG, "Polling for Result Request (" + pollingCount.toString() + ")");
}
Log.d(TAG, "Polling Service Finished");