本文介绍了ActivityNotFoundException:无法找到显式活动类服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是MainActivity和RecorderService Java类文件的外观.我也添加了AndroidManifest文件.

This is how my MainActivity and RecorderService Java class files looks like. I'm adding the AndroidManifest file too.

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?

I have added the service to the Manifest file. But still I'm getting the error: 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);

转到官方文档,以获取更多有关 Services的信息. > Android

Go to Official Docs for more information regard Services in Android

这篇关于ActivityNotFoundException:无法找到显式活动类服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-24 23:19