[android-developers] Re: Can't create handler inside thread that has not called Looper.prepare()
On Thursday, March 27, 2014 2:04:24 AM UTC-7, Yuvi wrote: > > You have to create your Handler in separate thread. > That's not really true. You can use the Handler constructor that takes a Looper so that its work gets scheduled the thread represented by that Looper. For example, you could create a Handler against the main thread's looper from any other thread like this: new Handler(Looper.getMainLooper()) Now that handler will schedule work on the main thread. Doug -- 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 --- You received this message because you are subscribed to the Google Groups "Android Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to android-developers+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[android-developers] Re: Can't create handler inside thread that has not called Looper.prepare()
Hi Rashmi, You have to create your Handler in separate thread. Then you can run that thread in your onCreate() of your Service2, like new LooperThread(); public Handler mHandler; // Your handler class LooperThread extends Thread { public void run() { Looper.prepare(); mHandler = new Handler() { public void handleMessage(Message msg) { // process incoming messages here } }; Looper.loop(); } } For more info you can look here http://developer.android.com/reference/android/os/Looper.html Regards, Yuvi On Wednesday, February 26, 2014 5:22:11 PM UTC+5:30, Rashmi wrote: > Hi, > > I am binding from service1 in app1 to service2 in app2 through aidl. In > service2 to I have defined the aidl stub api's which has some handler. > If I tried to access the service2 api through binder from service1, I am > getting the following exception > > "java.lang.RuntimeException: Can't create handler inside thread that has > not called Looper.prepare()" > > I am not creating any thread explicitly. Please let me know from where I > can call Looper.prepare(). > > Thank you, > > -- 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 --- You received this message because you are subscribed to the Google Groups "Android Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to android-developers+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[android-developers] Re: Can't create handler inside thread that has not called Looper.prepare()
It sounds like you are trying to do something that requires UI, in a service, which has no UI. You'll need to launch your Application in order to do whatever it is you are trying to do. Looper.prepare() is already called when you launch your main activity and you usually get this error when you try to do something that requires it, in a thread outside the loopers thread. You should also read up on how services and activities communicate. On Wednesday, 26 February 2014 06:52:11 UTC-5, Rashmi wrote: > > Hi, > > I am binding from service1 in app1 to service2 in app2 through aidl. In > service2 to I have defined the aidl stub api's which has some handler. > If I tried to access the service2 api through binder from service1, I am > getting the following exception > > "java.lang.RuntimeException: Can't create handler inside thread that has > not called Looper.prepare()" > > I am not creating any thread explicitly. Please let me know from where I > can call Looper.prepare(). > > Thank you, > > -- 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 --- You received this message because you are subscribed to the Google Groups "Android Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to android-developers+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.