[android-developers] Re: startActivity Problem

2009-07-30 Thread Yusuf T. Mobile

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 kolbys...@gmail.com 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-developers] Re: startActivity Problem

2009-07-30 Thread kolbysoft

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 yusuf.s...@t-mobile.com
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 kolbys...@gmail.com 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 

[android-developers] Re: startActivity Problem

2009-07-30 Thread Dianne Hackborn
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 kolbys...@gmail.com 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 yusuf.s...@t-mobile.com
 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 kolbys...@gmail.com 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}: