ActivityNotFoundException: 无法找到明确的 activity class 服务

ActivityNotFoundException: Unable to find explicit activity class service

这就是我的 MainActivity 和 RecorderService Java class 文件的样子。我也在添加 AndroidManifest 文件。

MainAcitivity.java

protected void onCreate(Bundle savedInstanceState) {

      btnSendSOS.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                sendSMS();

                Intent intent = new Intent(getBaseContext(), RecorderService.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(intent);

                finish();

                new CountDownTimer(5000, 1000) {

                @Override
                public void onTick(long millisUntilFinished) {

                }

                @Override
                public void onFinish() {
                    stopService(new Intent(getApplicationContext(), RecorderService.class));
                }
            }.start();
      });


}

RecorderService.java

public class RecorderService extends Service {
     // Service code here
}

AndroidManifest.xml

<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>

        <service android:enabled="true"
            android:name=".RecorderService" />
</application>

我已将服务添加到清单文件中。但我仍然收到错误:android.content.ActivityNotFoundException: Unable to find explicit activity class {.RecorderService}; have you declared this activity in your AndroidManifest.xml?

请帮帮我。提前致谢

RecorderService服务。不是 Activity。并且 Start Service 喜欢

  Intent i = new Intent(MainActivity.this, RecorderService.class);
  startService(i);

前往 Official Docs 了解有关 Android

Services 的更多信息