[android-developers] Re: android bindservice rotation

2012-06-05 Thread Greenhand
As for the broadcast solution, can an Activity receive a broadcast while it is rotating? Will all the broadcasts sent to it be received? About the Messenger, is it possible to create a Messenger from a Service to an Activity? In the Messenger tutorial, it says "it sends a Message to the service th

Re: [android-developers] Re: android bindservice rotation

2012-06-04 Thread Dianne Hackborn
Also, if you are writing an app where you have a service that is just being used by the code in that app (not being accessed by other apps), and not looking for the startService semantics... you should probably stop and make sure you really need a service at all. If you are just binding within yo

Re: [android-developers] Re: android bindservice rotation

2012-06-04 Thread Dianne Hackborn
Do please be careful about startService. You should only use one or the other where you want the associated semantics: - startService means "I want you do go off and do this work independently of the caller, with the understanding that someone will take care of stopping the service as soon as it

Re: [android-developers] Re: android bindservice rotation

2012-06-04 Thread Mark Murphy
On Mon, Jun 4, 2012 at 11:30 AM, Greenhand wrote: > If I use startService(), can the Activity communicate with the Service > and vice versa? startService() uses a variation of the command pattern: you "communicate" with the service via extras on the Intent passed to startService() as the command.

[android-developers] Re: android bindservice rotation

2012-06-04 Thread Greenhand
If I use startService(), can the Activity communicate with the Service and vice versa? On 6月4日, 下午11時15分, Mark Murphy wrote: > Don't use bindService(). Use startService(). > > On Mon, Jun 4, 2012 at 11:11 AM, Greenhand wrote: > > If I change the MessengerService into an media player service, a u

Re: [android-developers] Re: android bindservice rotation

2012-06-04 Thread Mark Murphy
Don't use bindService(). Use startService(). On Mon, Jun 4, 2012 at 11:11 AM, Greenhand wrote: > If I change the MessengerService into an media player service, a user > can control the media player by the ServiceConnection in the Activity > and the media player service can update the UI according

[android-developers] Re: android bindservice rotation

2012-06-04 Thread Greenhand
If I change the MessengerService into an media player service, a user can control the media player by the ServiceConnection in the Activity and the media player service can update the UI according to the state of media player. The downside is that the playback will be stopped when a user leaves the

[android-developers] Re: android bindservice rotation

2012-06-04 Thread Greenhand
Thank you! On 6月4日, 下午10時05分, Mark Murphy wrote: > Disable the button until it is usable. > > > > > > On Mon, Jun 4, 2012 at 9:57 AM, Greenhand wrote: > > It works! The context is so mysterious in Android. > > > Another question, in the tutorial (http://developer.android.com/guide/ > > topics/fu

Re: [android-developers] Re: android bindservice rotation

2012-06-04 Thread Mark Murphy
Disable the button until it is usable. On Mon, Jun 4, 2012 at 9:57 AM, Greenhand wrote: > It works! The context is so mysterious in Android. > > Another question, in the tutorial (http://developer.android.com/guide/ > topics/fundamentals/bound-services.html#Messenger), the mService is > not initi

[android-developers] Re: android bindservice rotation

2012-06-04 Thread Greenhand
It works! The context is so mysterious in Android. Another question, in the tutorial (http://developer.android.com/guide/ topics/fundamentals/bound-services.html#Messenger), the mService is not initialized and mBound is false until the mConnection callback is called. In the sayHello(), it uses "if

Re: [android-developers] Re: android bindservice rotation

2012-06-04 Thread Mark Murphy
On Mon, Jun 4, 2012 at 9:17 AM, Greenhand wrote: > In onDestroy(), I checked whether the Activity is finishing and bound. > If so, I unbindService(). > if(isFinishing() && serviceBound){ >    unbindService(serviceConnection); >    Log.d("MyMediaPlayerActivity","Activity: unbindService()"); > } Th

[android-developers] Re: android bindservice rotation

2012-06-04 Thread Greenhand
In onDestroy(), I checked whether the Activity is finishing and bound. If so, I unbindService(). if(isFinishing() && serviceBound){ unbindService(serviceConnection); Log.d("MyMediaPlayerActivity","Activity: unbindService()"); } On 6月4日, 下午9時04分, Greenhand wrote: > I added following two me

Re: [android-developers] Re: android bindservice rotation

2012-06-04 Thread Kostya Vasilyev
2012/6/4 Greenhand > if(serviceBound == false){ >bindService(new > Intent(getApplicationContext(),MessengerService.class), > serviceConnection, BIND_AUTO_CREATE); //!!! >Log.d("MyMediaPlayerActivity","Activity: bindService()"); > }else{ >Log.d("MyMediaPlayerActivity","Activity: servic

[android-developers] Re: android bindservice rotation

2012-06-04 Thread Greenhand
I added following two methods in my Activity: @Override protected void onSaveInstanceState(Bundle outState) { outState.putBoolean("serviceBound", serviceBound); } @Override public Object onRetainNonConfigurationInstance() { return serviceConnection; } And in onCreate() of the Activity, I ad

Re: [android-developers] Re: android bindservice rotation

2012-06-04 Thread Mark Murphy
On Mon, Jun 4, 2012 at 5:06 AM, Greenhand wrote: > 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

Re: [android-developers] Re: android bindservice rotation

2012-06-04 Thread Kostya Vasilyev
Why use addition instead of multiplication? -- K 04.06.2012 14:06, sha m написал: why shouldnt startservice/stopservice instead of bind/unbinding to the service -- Kostya Vasilyev -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To pos

Re: [android-developers] Re: android bindservice rotation

2012-06-04 Thread sha m
why shouldnt startservice/stopservice instead of bind/unbinding to the service On Mon, Jun 4, 2012 at 3:15 PM, Kostya Vasilyev wrote: > > 04.06.2012 13:06, Greenhand написал: > > I modify my code and use bindService(new >> Intent(getApplicationContext()**, MessengerService.class), mConnection

Re: [android-developers] Re: android bindservice rotation

2012-06-04 Thread Kostya Vasilyev
04.06.2012 13:06, Greenhand написал: 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

[android-developers] Re: android bindservice rotation

2012-06-04 Thread Greenhand
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 t