java - Android 服务变红

标签 java android intentservice

我想向我的 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 ,但是 .TygoIntentServiceTygoIntentService.java 没有我的应用程序的默认构造函数。如果我运行它,它就可以工作,但我想知道这是否会在将来带来任何问题,以及它是否可以满足我需要做的事情。

最佳答案

从构造函数中删除String name参数:

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

关于java - Android 服务变红,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29167267/

相关文章:

java - 将 Android 应用程序连接到 Google Cloud Endpoints : could not find class 时出错

android - 广播接收器对 Activity 的 Intent ?

android - 如何测试 IntentService android?

android - 如何通过按下应用程序小部件来启动 IntentService

Android Geofence 无法调用 IntentService 并且无法在 BroadcastReceiver 中工作

java - 抽屉导航项目图标未显示原始颜色

java - 在 Clojure 中制作缩略图

Java 初级扫描仪

java - spring mvc 错误: class <> nor any of its super class is known to this context

android - 依赖项是最新的,但 Gradle 认为不是