Consider such Android code in a Service implementing a Listener (events from orientation sensor):
public void onStateChanged()
{
//do some work
stopSelf();
}
I want the service to die AFTER the method onStateChanged()
is triggered and AFTER its code is executed. However, it dies too soon - stopSelf()
is being called BEFORE the "//do some work"
occurs. If I place a break during the de开发者_StackOverflow社区bug somewhere inside "//do some work"
everything works fine - code is executed, then service dies. If I remove stopSelf()
- code is executed. If i run it the way above - NOTHING from "//do some work"
gets done. Why is that? How's that possible?
It's possible they occur in another thread. Some methods return straight away while their work is done concurrently. Depends on the "work". There might be a relevant onSomethingCompletedListener that you can use. Show us the code you've tried! And try inserting Log.d("blah"); statements to get more information.
精彩评论