Um, I can't reproduce this with my devices at this time -- but
remember seeing this on one of them for a service that returned 0
(i.e. START_STICKY_COMPATIBILITY).

That was a few months, and a few firmware updates ago.

I'd just put an "if" in your code and be done with it.

-- Kostya

19 декабря 2011 г. 16:19 пользователь Terry <[email protected]> написал:
> Thank you, Kostya - for sending me in the right direction.
>
> I now understand that the NullPointer Exception (I asked about) should
> be expected by any Service, as the Android system may restart it with
> a null intent - on purpose. However, after I have done some debugging
> using DDMS, I am unable to reproduce this behavior. when I stop a
> process, the service (in the process) always seems to be restarted by
> redelivering the originally used intent, regardless of whether
> START_STICKY, START_STICKY_COMPATIBILITY or START_REDELIVER_INTENT was
> returned from onStartCommand().
>
> Interested developers should also read
> http://android-developers.blogspot.com/2010/02/service-api-changes-starting-with.html
>
> Terry.
>
>
> On 15 Des, 18:05, Terry <[email protected]> wrote:
>> I followed your advice, and used DDMS to stop the process of an app in
>> question.
>> Interestingly, it did not crash, but the Service was restarted
>> properly, without any error messages shown to the user.
>> The value START_STICKY is being (and has always been) returned from
>> method onStartCommand().
>> So the problem is caused by something else - I guess.
>>
>> Terry
>>
>> On Dec 15, 2:43 pm, Kostya Vasilyev <[email protected]> wrote:
>>
>>
>>
>>
>>
>>
>>
>> > Well, maybe you should return START_NOT_STICKY, or
>> > START_REDELIVER_INTENT, or add an if statement checking for null - it
>> > just depends on the service.
>>
>> > Read the docs, run your own experiments with DDMS, then decide what is
>> > the right thing to do for your code.
>>
>> > The DDMS Perspective in Eclipse is under Window / Open Perspective /
>> > Other... / DDMS. The Devices tab lets you terminate your own apps's
>> > processes.
>>
>> > -- Kostya
>>
>> > 15 ÄÅËÁÂÒÑ 2011šÇ. 17:28 ÐÏÌØÚÏ×ÁÔÅÌØ Terry <[email protected]> ÎÁÐÉÓÁÌ:
>>
>> > > And what is the DDMS tab in Eclipse?
>>
>> > > Terry
>>
>> > > On Dec 15, 2:00špm, Terry <[email protected]> wrote:
>> > >> Thank, Kostya.
>>
>> > >> So, you mean that I should return START_STICKY_COMPATIBILITY to avoid
>> > >> this problem?
>>
>> > >> But the actual problem then probably lies somewhere else, which may
>> > >> cause the process to fail/stop in the first place.
>> > >> It could be some Exception. Why are they not registered?
>>
>> > >> Terry
>>
>> > >> On 15 Des, 11:59, Kostya Vasilyev <[email protected]> wrote:
>>
>> > >> >http://developer.android.com/reference/android/app/Service.html#onSta...,
>> > >> > int, int)
>> > >> > <http://developer.android.com/reference/android/app/Service.html#onSta...>
>>
>> > >> > š>>
>> > >> > intent šThe Intent supplied to|startService(Intent)
>> > >> > <http://developer.android.com/reference/android/content/Context.html#s...>|,
>> > >> > as given. *This may be null *if the service is being restarted after 
>> > >> > its
>> > >> > process has gone away, and it had previously returned anything
>> > >> > except|START_STICKY_COMPATIBILITY
>> > >> > <http://developer.android.com/reference/android/app/Service.html#START...>|.
>>
>> > >> > <<
>>
>> > >> > I believe the above statement is not quite correct about when the 
>> > >> > intent
>> > >> > may be null, please see this as well:
>>
>> > >> >http://developer.android.com/reference/android/app/Service.html#START...
>>
>> > >> > You can try reproducing the issue on your development device by using
>> > >> > the DDMS tab in Eclipse in killing the service's process. When Android
>> > >> > restarts the service a bit later, check the intent.
>>
>> > >> > -- Kostya
>>
>> > >> > 15.12.2011 14:36, Terry ?????:
>>
>> > >> > > Occationally users report a NullPointerException Error at
>> > >> > > MyService.onStartCommand() for some of my apps.
>> > >> > > I never see this error when I try to debug the apps, and I wonder 
>> > >> > > why
>> > >> > > this happens.
>> > >> > > I have studied the code both for the methods onStartCommand() and
>> > >> > > onCreate() for the services in question, but I seem unable to find 
>> > >> > > the
>> > >> > > cause of the problem. I suspect that the actual reason for the crash
>> > >> > > lies elsewhere.
>>
>> > >> > > Here is the stack trace, which seems to be identical for all crashes
>> > >> > > on ALL of the apps in question:
>>
>> > >> > > java.lang.RuntimeException: Unable to start service
>> > >> > > xxxx.xxxx.xxxx.MyService@405274c8 with null:
>> > >> > > java.lang.NullPointerException
>> > >> > > at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:
>> > >> > > 2481)
>> > >> > > at android.app.ActivityThread.access$2800(ActivityThread.java:145)
>> > >> > > at android.app.ActivityThread$H.handleMessage(ActivityThread.java:
>> > >> > > 1118)
>> > >> > > at android.os.Handler.dispatchMessage(Handler.java:99)
>> > >> > > at android.os.Looper.loop(Looper.java:150)
>> > >> > > at android.app.ActivityThread.main(ActivityThread.java:4369)
>> > >> > > at java.lang.reflect.Method.invokeNative(Native Method)
>> > >> > > at java.lang.reflect.Method.invoke(Method.java:507)
>> > >> > > at com.android.internal.os.ZygoteInit
>> > >> > > $MethodAndArgsCaller.run(ZygoteInit.java:846)
>> > >> > > at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:604)
>> > >> > > at dalvik.system.NativeStart.main(Native Method)
>> > >> > > Caused by: java.lang.NullPointerException
>> > >> > > at xxxx.xxxx.xxxx.MyService.onStartCommand(MyService.java:279)
>> > >> > > at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:
>> > >> > > 2464)
>>
>> > >> > > As the Google error report system does not include device type or
>> > >> > > Android os version, I do not know if this occurs only one some
>> > >> > > specific devices or os version.
>>
>> > >> > > Has anyone got an idea as to what is happening?
>>
>> > >> > > Thank you.
>> > >> > > Terry
>>
>> > >> > --
>> > >> > Kostya Vasilyev
>>
>> > > --
>> > > 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
>
> --
> 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

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