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