我想向我的 list 添加一项服务,但它发出警告。
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.aura_apps.tygo_asbroek.intentexample" >
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".SecondActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service
android:name=".TygoIntentService"
>
</service>
</application>
这是Java代码:
package com.aura_apps.tygo_asbroek.intentexample;
public class TygoIntentService extends IntentService {
private static final String TAG = "com.bluelionapps.intentexample";
public TygoIntentService(String name) {
super("TygoIntentService");
}
@Override
protected void onHandleIntent(Intent intent) {
//This is what the service does
Toast toast = Toast.makeText(getApplicationContext(), "Service Lauched", Toast.LENGTH_SHORT);
toast.show();
}
}
在这里您可以看到我的完整 list ,但是 .TygoIntentService
说 TygoIntentService.java
没有我的应用程序的默认构造函数。如果我运行它,它就可以工作,但我想知道这是否会在将来带来任何问题,以及它是否可以满足我需要做的事情。
最佳答案
从构造函数中删除String name
参数:
public TygoIntentService() {
super("TygoIntentService");
}
关于java - Android 服务变红,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29167267/