Thanks Mark. Actually the code I posted missed out the 'onStart' method
details that I actually tried. Here is the actual 'onStart' method of the
MyService class I used where I create the thread and starting it.


    @Override
    public void onStart(Intent intent, int startId) {
        System.out.println ("MyService  ))))))))))))))))))))))))))");
        super.onStart(intent, startId);
        Thread t = new Thread(this);
        t.start();
    }

I modified the run method I put some System.out. statement inside a
while(true) loop. The idea was to keep this service running as long as the
device is on. But it looks like the system is sending a SIG 9 to kill the
process (process id 697) for the 'service'. Here is the logcat lines that I
see.

D/installd(  557): DexInv: --- BEGIN '/data/app/vmdl51510.tmp' ---
I/System.out(  697): =====>: inside the run method....Count = 49
I/System.out(  697): =====>: inside the run method....Count = 50
D/dalvikvm(  722): DexOpt: load 41ms, verify 52ms, opt 1ms
D/installd(  557): DexInv: --- END '/data/app/vmdl51510.tmp' (success) ---
D/PackageManager(  583):   Services: com.bn.InStoreWifiConnectivityManager
D/PackageManager(  583):   Receivers: com.bn.InStoreWiFiServiceInitiator
I/System.out(  697): =====>: inside the run method....Count = 51
I/installd(  557): move /data/dalvik-cache/d...@app
@[email protected] -> /data/dalvik-cache/d...@app
@[email protected]
D/PackageManager(  583): New package installed in /data/app/com.bn.apk
I/System.out(  697): =====>: inside the run method....Count = 52
D/AndroidRuntime(  708): Shutting down VM
D/dalvikvm(  708): DestroyJavaVM waiting for non-daemon threads to exit
D/dalvikvm(  708): DestroyJavaVM shutting VM down
D/dalvikvm(  708): HeapWorker thread shutting down
D/dalvikvm(  708): HeapWorker thread has shut down
D/jdwp    (  708): JDWP shutting down net...
D/dalvikvm(  708): VM cleaning up
D/dalvikvm(  708): LinearAlloc 0x0 used 627404 of 4194304 (14%)
D/ActivityManager(  583): Uninstalling process com.bn
I/System.out(  697): =====>: inside the run method....Count = 53
D/ActivityManager(  583): Force removing process ProcessRecord{436ea918 697:
com.bn/10020} (com.bn/10020)
W/ActivityManager(  583): Scheduling restart of crashed service
com.mypackage/.MyService in 5000ms
I/Process (  583): Sending signal. PID: 697 SIG: 9
D/ActivityManager(  583): Received spurious death notification for thread
android.os.binderpr...@436c0898
E/ActivityThread(  583): Failed to find provider info for
android.server.checkin
W/Checkin (  583): Can't log event SYSTEM_SERVICE_LOOPING:
java.lang.IllegalArgumentException: Unknown URL
content://android.server.checkin/events

Looks the process Id 583 is the one that sends SIG 9. Any idea why this is
happening?

Thanks

Ravi

On Mon, Aug 3, 2009 at 4:58 AM, Mark Murphy <[email protected]> wrote:

>
> R Ravichandran wrote:
> > This is  definitely a viable approach for my application architecture,
> > but still strugglng to make this work. Here are some details, and I am
> > hoping that someone will point out what is going wrong here.
> >
> > 1. I have a class "MyServiceInitiator" that is hooked up to the
> > BOOT_COMPLETED action.
> >
> >
> > public class MyServiceInitiator extends BroadcastReceiver {
> >
> >     private ServiceConnection mConnection = new ServiceConnection() {
> >         public void onServiceConnected(ComponentName className, IBinder
> > service) {
> >         }
> >
> >         public void onServiceDisconnected(ComponentName className) {
> >          }
> >     };
>
> You cannot call bindService() from a BroadcastReceiver. You can call
> startService() from a BroadcastReceiver, as you doing below. Hence you
> do not need a ServiceConnection object, since that is only used with
> bindService().
>
> > public class MyService extends Service implements Runnable {
> >
> >
> >     @Override
> >     public void onCreate() {
> >         System.out.println ("MyService:
> > onCreate()================================================");
> >     }
>
> You need to chain to super.onCreate(). Also, please consider using
> android.util.Log instead of System.out.
>
> >
> >     @Override
> >     public IBinder onBind(Intent arg0) {
> >         // TODO Auto-generated method stub
> >         System.out.println ("MyService:
> > onBind()================================================");
> >         doScan();
> >         return null;
> >     }
>
> This will never be called, since you are not using bindService().
>
> >     @Override
> >     public boolean onUnbind(Intent intent) {
> >         System.out.println
> > ("onUnbind()================================================");
> >         return super.onUnbind(intent);
> >     }
> >
> >     public class LocalBinder extends Binder {
> >         MyService getService() {
> >             return MyService.this;
> >         }
> >     }
> >
> >
> >     @Override
> >     public void onRebind(Intent intent) {
> >         super.onRebind(intent);
> >     }
>
> Those will never be used, since you are not calling bindService().
>
> >     @Override
> >     public void run() {
> >         try {
> >             System.out.println ("MyService(): inside the run
> method....");
> >             Thread.currentThread().sleep(1000);
> >         }
> >         catch(InterruptedException iex) {
> >             iex.printStackTrace();
> >         }
> >
> >     }
>
> This will never be used, as you are not starting a thread.
>
> > I need to use a thread to do some background process that does not seem
> > to run at all. The android documentation stays clearly that we should
> > spawn our own threads if we need to perform long standing operations.
>
> That is true. You are not spawning a thread.
>
> > I also see this log cat out that clearly shows that the process
> > corresponding to the service crashed:
> >
> > D/ActivityManager(  584): Force removing process ProcessRecord{43701018
> > 703:com.bn/10020 <http://com.bn/10020>} (com.bn/10020 <
> http://com.bn/10020>)
> > W/ActivityManager(  584): Scheduling restart of crashed service
> > com.mypackage/.MyService in 5000ms
> > I/Process (  584): Sending signal. PID: 703 SIG: 9
>
> This is not an exception. Look in your logcat output for a Java stack
> trace to see where the exception is.
>
> --
> Mark Murphy (a Commons Guy)
> http://commonsware.com | http://twitter.com/commonsguy
>
> Looking for Android opportunities? http://wiki.andmob.org/hado
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to