I modify my code and use bindService(new Intent(getApplicationContext(), MessengerService.class), mConnection, Context.BIND_AUTO_CREATE) but my service still be killed and created with my Activity life cycle. Can you please illustrate "Don't unbind in the old activity instance -- only unbind from the new one." more clearly, such as some code fragments?
I have never used a fragement. Is it different from Activity when it comes to handling bound service on rotation? On 6月3日, 下午10時08分, Mark Murphy <mmur...@commonsware.com> wrote: > On Sun, Jun 3, 2012 at 10:04 AM, Greenhand <cooperateonl...@gmail.com> wrote: > > For thecommunicationbetweenActivityandService, Ifollowedthe > >http://developer.android.com/guide/topics/fundamentals/bound-services... > > to implement anActivitythat binds aService. > > However, theServicewill be killed and created when theActivityis > > rotating. Is there a way to keep theServicerunning while rotating? > > Don't unbind in the oldactivityinstance -- only unbind from the new > one. This will require you to bind using the Application object > instead of some other Context. See: > > http://commonsware.com/blog/2010/09/29/another-use-getapplicationcont... > > https://groups.google.com/group/android-developers/browse_frm/thread/... > > A retained fragment, instead of onRetainNonConfigurationInstance(), > would be a variation on this pattern. > > -- > Mark Murphy (a Commons > Guy)http://commonsware.com|http://github.com/commonsguyhttp://commonsware.com/blog|http://twitter.com/commonsguy > > Android Training...At Your Office:http://commonsware.com/training > > -- 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