Hi all,
I'm trying to call a service directly, and I'm getting an
ActivityNotFoundException thrown.

My main class looks like this:
-------------------------------------------------------------------------------------------------------------------------------
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        PackageManager pm = getPackageManager();
        try {
          Log.i(TAG,"retrieving services:");
          PackageInfo pinfo = pm.getPackageInfo("test.another",
PackageManager.GET_ACTIVITIES | PackageManager.GET_SERVICES);
          for (ServiceInfo serv : pinfo.services) {
            Log.i(TAG,"declared service: "+serv.name);
            Log.i(TAG,"  package name: "+serv.packageName);
            Log.i(TAG,"  enabled: "+serv.enabled);
            Log.i(TAG,"  exported: "+serv.exported);
          }
        } catch (NameNotFoundException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }

        Intent i = new Intent();
        i.setClassName("test.another", "test.another.MyService");
        startActivity(i);
        setContentView(R.layout.main);
    }
-------------------------------------------------------------------------------------------------------------

My service is empty, minus some log messages:

------------------------------------------------------------------------------------------------------------
  public void onCreate() {
    Log.i(T,"created");
  }

  public void onStart(Intent i, int code) {
    Log.i(T,"started");
  }

  @Override
  public IBinder onBind(Intent intent) {
    // TODO Auto-generated method stub
    return null;
  }
------------------------------------------------------------------------------------------------------------

And the service is declared in the manifest file:
---------------------------------------------------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android";
      package="test.another"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/
app_name">
        <activity android:name=".Main"
                  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="MyService"></service>
</application>
    <uses-sdk android:minSdkVersion="3" />
</manifest>

--------------------------------------------------------------------------------------------------------------------

When I run it in either the emulator or on my phone, I get this log:

--------------------------------------------------------------------------------------------------------------------
07-30 10:56:52.676: INFO/main(1686): retrieving services:
07-30 10:56:52.686: INFO/main(1686): declared service:
test.another.MyService
07-30 10:56:52.686: INFO/main(1686):   package name: test.another
07-30 10:56:52.696: INFO/main(1686):   enabled: true
07-30 10:56:52.696: INFO/main(1686):   exported: false
07-30 10:56:52.696: INFO/ActivityManager(56): Starting activity:
Intent { comp={test.another/test.another.MyService} }
07-30 10:56:52.716: DEBUG/AndroidRuntime(1686): Shutting down VM
07-30 10:56:52.716: WARN/dalvikvm(1686): threadid=3: thread exiting
with uncaught exception (group=0x4000fe70)
07-30 10:56:52.716: ERROR/AndroidRuntime(1686): Uncaught handler:
thread main exiting due to uncaught exception
07-30 10:56:52.746: DEBUG/dalvikvm(1622): GC freed 5960 objects /
376680 bytes in 423ms
07-30 10:56:52.746: ERROR/AndroidRuntime(1686):
java.lang.RuntimeException: Unable to start activity ComponentInfo
{test.another/test.another.Main}:
android.content.ActivityNotFoundException: Unable to find explicit
activity class {test.another/test.another.MyService}; have you
declared this activity in your AndroidManifest.xml?
07-30 10:56:52.746: ERROR/AndroidRuntime(1686):     at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
2268)
07-30 10:56:52.746: ERROR/AndroidRuntime(1686):     at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:
2284)
07-30 10:56:52.746: ERROR/AndroidRuntime(1686):     at
android.app.ActivityThread.access$1800(ActivityThread.java:112)
07-30 10:56:52.746: ERROR/AndroidRuntime(1686):     at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1692)
07-30 10:56:52.746: ERROR/AndroidRuntime(1686):     at
android.os.Handler.dispatchMessage(Handler.java:99)
07-30 10:56:52.746: ERROR/AndroidRuntime(1686):     at
android.os.Looper.loop(Looper.java:123)
07-30 10:56:52.746: ERROR/AndroidRuntime(1686):     at
android.app.ActivityThread.main(ActivityThread.java:3948)
07-30 10:56:52.746: ERROR/AndroidRuntime(1686):     at
java.lang.reflect.Method.invokeNative(Native Method)
07-30 10:56:52.746: ERROR/AndroidRuntime(1686):     at
java.lang.reflect.Method.invoke(Method.java:521)
07-30 10:56:52.746: ERROR/AndroidRuntime(1686):     at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run
(ZygoteInit.java:782)
07-30 10:56:52.746: ERROR/AndroidRuntime(1686):     at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
07-30 10:56:52.746: ERROR/AndroidRuntime(1686):     at
dalvik.system.NativeStart.main(Native Method)
07-30 10:56:52.746: ERROR/AndroidRuntime(1686): Caused by:
android.content.ActivityNotFoundException: Unable to find explicit
activity class {test.another/test.another.MyService}; have you
declared this activity in your AndroidManifest.xml?
07-30 10:56:52.746: ERROR/AndroidRuntime(1686):     at
android.app.Instrumentation.checkStartActivityResult
(Instrumentation.java:1480)
07-30 10:56:52.746: ERROR/AndroidRuntime(1686):     at
android.app.Instrumentation.execStartActivity(Instrumentation.java:
1454)
07-30 10:56:52.746: ERROR/AndroidRuntime(1686):     at
android.app.Activity.startActivityForResult(Activity.java:2656)
07-30 10:56:52.746: ERROR/AndroidRuntime(1686):     at
test.another.Main.onCreate(Main.java:38)
07-30 10:56:52.746: ERROR/AndroidRuntime(1686):     at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:
1123)
07-30 10:56:52.746: ERROR/AndroidRuntime(1686):     at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
2231)
07-30 10:56:52.746: ERROR/AndroidRuntime(1686):     ... 11 more

-------------------------------------------------------------------------------------------------------------------------------

I'm at my wits end here, but to make matters worse, I have an old
project with the same code that works fine. I dumped my development
environment, re-installed everything, still no dice.


Any help would be greatly appreciated,
Michael
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to