android-ActivityNotFoundException尝试启动服务时.

android-ActivityNotFoundException尝试启动服务时.,第1张

概述尝试启动服务时出现“找不到活动”异常.我已经在清单中注册了服务.添加我认为是相关的代码和LogCat.让我知道是否需要查看更多内容.01-2917:41:51.4409196-9196/drvr.drvlogE/AndroidRuntime﹕FATALEXCEPTION:mainProcess:drvr.drvlog,PID:9196android.content.Activ

尝试启动服务时出现“找不到活动”异常.我已经在清单中注册了服务.添加我认为是相关的代码和LogCat.让我知道是否需要查看更多内容.

01-29 17:41:51.440    9196-9196/drvr.drvlog E/AndroIDRuntime﹕ FATAL EXCEPTION: mainProcess: drvr.drvlog, PID: 9196androID.content.ActivityNotFoundException: Unable to find explicit activity class {drvr.drvlog/drvr.drvlog.GPSService}; have you declared this activity in your AndroIDManifest.xml?        at androID.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1719)        at androID.app.Instrumentation.execStartActivity(Instrumentation.java:1491)        at androID.app.Activity.startActivityForResult(Activity.java:3436)        at androID.app.Activity.startActivityForResult(Activity.java:3393)        at androID.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:817)        at androID.app.Activity.startActivity(Activity.java:3644)        at androID.app.Activity.startActivity(Activity.java:3607)        at drvr.drvlog.HomeScreen.startDrive(HomeScreen.java:60)        at drvr.drvlog.HomeScreen.onClick(HomeScreen.java:46)        at androID.vIEw.VIEw.performClick(VIEw.java:4456)        at androID.vIEw.VIEw$PerformClick.run(VIEw.java:18465)        at androID.os.Handler.handleCallback(Handler.java:733)        at androID.os.Handler.dispatchMessage(Handler.java:95)        at androID.os.Looper.loop(Looper.java:136)        at androID.app.ActivityThread.main(ActivityThread.java:5086)        at java.lang.reflect.Method.invokeNative(Native Method)        at java.lang.reflect.Method.invoke(Method.java:515)        at com.androID.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)        at com.androID.internal.os.ZygoteInit.main(ZygoteInit.java:601)        at dalvik.system.NativeStart.main(Native Method)

我的服务类别:

public class GPSService extends Service implements LocationListener {SharedPreferences sp;Utils util;LocationManager locationManager;DataBaseHelper db;long driveID;//empty constructor.public GPSService() {}@OverrIDepublic int onStartCommand(Intent intent, int flags, int startID) {    util = new Utils();    sp = getSharedPreferences(util.APP_DATA, 0);    locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);    db = new DataBaseHelper(this);    boolean driving = sp.getBoolean(util.DRIVING, false);    if (intent != null) {        if (intent.getAction() == util.Stop_DRIVE) {            if (driving)                stopDrive();        } else if (intent.getAction() == util.START_DRIVE) {            if (!driving)                startDrive();        }    }    return START_REDEliVER_INTENT;}

我正在从片段内部调用启动服务.这是我开始服务的地方.

private voID startDrive(){    Log.w("rakshak", "Start drive clicked");    Intent intent = new Intent(getActivity(), GPSService.class);    intent.setAction(util.START_DRIVE);    getActivity().startActivity(intent);}private voID stopDrive(){    Log.w("rakshak","Stop Drive clicked");    Intent intent = new Intent(getActivity(), GPSService.class);    intent.setAction(util.Stop_DRIVE);    getActivity().startService(intent);}

在清单中,我的应用程序标签中有这个

<service androID:name=".GPSService"></service>

我的问题是:
在清单中注册了服务后,为什么会收到注册服务的错误消息,该如何解决?

让我知道您是否需要更多信息.干杯.

解决方法:

您的方法startDrive错误

private voID startDrive(){    Log.w("rakshak", "Start drive clicked");    Intent intent = new Intent(getActivity(), GPSService.class);    intent.setAction(util.START_DRIVE);    getActivity().startActivity(intent);}

您使用的是startActivity而不是startService.另外stopDrive()再次启动服务

总结

以上是内存溢出为你收集整理的android-ActivityNotFoundException尝试启动服务时.全部内容,希望文章能够帮你解决android-ActivityNotFoundException尝试启动服务时.所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1094059.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-28
下一篇2022-05-28

发表评论

登录后才能评论

评论列表(0条)

    保存