Question

I am developing a library for Android. This lib consist of a custom view. I'd like to be able to detect from my lib when onConfigurationChanged() is called for the activity.

My first thought was to use startActivity() with my own activity that only implement onConfigurationChanged(), but unfortunatly this start a new activity on top of the application. Is it possible to run an activity in "background"?

Maybe I am having the wrong approach? Do you have any idea of how I can achieve this?

Était-ce utile?

La solution

So the way I was trying to solve it wasn't googd.

I added a method onConfigurationChanged() to my lib. That way, people using it will have to call this method from their activity.

Problem solved!

Autres conseils

I had a similar problem - a custom Gallery that created its own dialog and needed to track configuration changes (for it leaked its views when orientation changed).

To solve this, dialog.dismiss() must had to be called when such a change was detected. I already needed main activity to call some methods of the custom view, onContextItemSelected and onActivityResult for instance.

I would like something more transparent to users. In this particular case, I achieved this by calling the dismiss method from the onSaveInstanceState from View (not from Activity), and keep the caller activity intact without having to call any more methods from the custom view.

You need to define in your manifest that the activity handles the onConfiguratoinChange and then define it in your code. You can check out the Google docs here for an example. http://developer.android.com/guide/topics/resources/runtime-changes.html

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top