Thursday, July 29, 2010

[android-developers] Re: bindService() does not create local service, but returns true

Thank you so much, Kostya! Indeed it turns out to be an asynchronous
call. It makes the design of the Activity slightly more verbose, but
at least I got it working. Are there imperative reasons why the
service is not returned synchronously? Is it very costly to
(instantiate and) return a local Service? If not, it would be a nice
feature to have the bindService block, or at least to have the option
through a method parameter that we want to wait for it like
bindService(..., boolean willWait).

Thanks again!

Jeroen

On 29 jul, 22:32, Kostya Vasilyev <kmans...@gmail.com> wrote:
> If I remember right, starting a service is asynchronous vs. the call to
> bindService, and so are the callbacks in ServiceConnection.
>
> This means if you call the service on the next line after bindService,
> you'll get a null pointer exception.
>
> Also make sure your Service subclass doesn't fail to instantiate (due to
> unresolved references or variable initializers). If the object can't be
> created, it will never get to onCreate.
>
> --
> Kostya Vasilyev --http://kmansoft.wordpress.com
>
> 30.07.2010 0:21 пользователь "Jeroen Kransen" <jer...@kransen.nl> написал:
>
> This is the only serious logging I get in LogCat. Sometimes after that
> I get a timeout on the Service, so maybe it is running, I just don't
>
> get a reference to it.
> 07-29 22:17:15.485: WARN/WindowManager(166): Force clearing freeze:
> AppWindowToken{46ad1860 token=HistoryRecord{465c3f50
> nl.kransen.consumption.android/.ViewTrendActivity}}
> 07-29 22:17:17.625: DEBUG/dalvikvm(166): GC freed 14677 objects /
> 990168 bytes in 142ms
> 07-29 22:17:19.921: WARN/ActivityManager(166): Launch timeout has
> expired, giving up wake lock!
> 07-29 22:17:20.599: WARN/ActivityManager(166): Activity idle timeout
> for HistoryRecord{465c3f50
> nl.kransen.consumption.android/.ViewTrendActivity}
> 07-29 22:17:25.685: DEBUG/dalvikvm(11731): GC freed 3116 objects /
> 286000 bytes in 82ms
> 07-29 22:17:34.597: DEBUG/AndroidRuntime(1139): Shutting down VM
> 07-29 22:17:34.597: WARN/dalvikvm(1139): threadid=3: thread exiting
> with uncaught exception (group=0x4001b390)
> 07-29 22:17:34.606: ERROR/AndroidRuntime(1139): Uncaught handler:
> thread main exiting due to uncaught exception
> 07-29 22:17:34.656: ERROR/AndroidRuntime(1139):
> java.lang.RuntimeException: Unable to start activity
> ComponentInfo{nl.kransen.consumption.android/
> nl.kransen.consumption.android.ViewTrendActivity}:
> java.lang.NullPointerException
> 07-29 22:17:34.656: ERROR/AndroidRuntime(1139):     at
> android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
> 2596)
> 07-29 22:17:34.656: ERROR/AndroidRuntime(1139):     at
> android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:
> 2621)
> 07-29 22:17:34.656: ERROR/AndroidRuntime(1139):     at
> android.app.ActivityThread.access$2200(ActivityThread.java:126)
> 07-29 22:17:34.656: ERROR/AndroidRuntime(1139):     at
> android.app.ActivityThread$H.handleMessage(ActivityThread.java:1932)
> 07-29 22:17:34.656: ERROR/AndroidRuntime(1139):     at
> android.os.Handler.dispatchMessage(Handler.java:99)
> 07-29 22:17:34.656: ERROR/AndroidRuntime(1139):     at
> android.os.Looper.loop(Looper.java:123)
> 07-29 22:17:34.656: ERROR/AndroidRuntime(1139):     at
> android.app.ActivityThread.main(ActivityThread.java:4595)
> 07-29 22:17:34.656: ERROR/AndroidRuntime(1139):     at
> java.lang.reflect.Method.invokeNative(Native Method)
> 07-29 22:17:34.656: ERROR/AndroidRuntime(1139):     at
> java.lang.reflect.Method.invoke(Method.java:521)
> 07-29 22:17:34.656: ERROR/AndroidRuntime(1139):     at
> com.android.internal.os.ZygoteInit
> $MethodAndArgsCaller.run(ZygoteInit.java:860)
> 07-29 22:17:34.656: ERROR/AndroidRuntime(1139):     at
> com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
> 07-29 22:17:34.656: ERROR/AndroidRuntime(1139):     at
> dalvik.system.NativeStart.main(Native Method)
> 07-29 22:17:34.656: ERROR/AndroidRuntime(1139): Caused by:
> java.lang.NullPointerException
> 07-29 22:17:34.656: ERROR/AndroidRuntime(1139):     at
> nl.kransen.consumption.android.ViewTrendActivity.onCreate(ViewTrendActivity.java:
> 44)
> 07-29 22:17:34.656: ERROR/AndroidRuntime(1139):     at
> android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:
> 1047)
> 07-29 22:17:34.656: ERROR/AndroidRuntime(1139):     at
> android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
> 2544)
> 07-29 22:17:34.656: ERROR/AndroidRuntime(1139):     ... 11 more
>
> On 29 jul, 22:13, Jeroen Kransen <jer...@kransen.nl> wrote:
>
> > Please help anybody. I create a loca...

--
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+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment