There was never a point at any stage in the development of the platform where startActivity() would start a Service. :)
On Thu, Jul 30, 2009 at 10:21 AM, kolbysoft <[email protected]> wrote: > > Thanks Yusuf, > > that worked. > Still curious though, when did the startActivity behavior change? It > worked in an older project that was also 1.5. > > Michael > > On Jul 30, 11:52 am, "Yusuf T. Mobile" <[email protected]> > wrote: > > Try using startService() to start your service instead of startActivity > > (). > > > > Yusuf Saib > > Android > > ·T· · ·Mobile· stick together > > The views, opinions and statements in this email are those of the > > author solely in their individual capacity, and do not necessarily > > represent those of T-Mobile USA, Inc. > > > > On Jul 30, 8:06 am, kolby <[email protected]> wrote: > > > > > > > > > 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 > > > -- Dianne Hackborn Android framework engineer [email protected] Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails. All such questions should be posted on public forums, where I and others can see and answer them. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---

