0

I am building an application (aidl service) that will be called through code in an Activity (Activity will be written by someone else and I have no control over it).

Activity creates a binding to the service, call methods on the service and get the result back via callbacks.

If the activity orientation changes, it will have to bind to the service again, but the previous callbacks will be lost.

What is the best way to handle activity orientation changes on the binded service.

dcanh121
  • 4,665
  • 11
  • 37
  • 84

1 Answers1

0

Several options, depending on the situation:

1) Have the Activity handle orientation change itself instead of letting Android kill and recreate the Activity. If the Activity has a lot of state, then this is often a good thing to do anyway.

2) Have the killed Activity hand off the Binder (reference to the Service) to the newly created Activity. This can be done using a NonConfigurationInstance.

3) Store the Binder (reference to the Service) in a static variable that can be accessed from any class (this can cause memory leaks, but is usually relatively safe).

4) Upon successful rebinding, the Service can send back all of its current "state" to the new Activity (which may be enough, depending upon what you use callbacks for).

David Wasser
  • 93,459
  • 16
  • 209
  • 274