1

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?

Adinia
  • 3,722
  • 5
  • 40
  • 58
eFyx
  • 21
  • 4

3 Answers3

1

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.

Tarc
  • 3,214
  • 3
  • 29
  • 41
1

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!

eFyx
  • 21
  • 4
0

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

Carth
  • 2,303
  • 1
  • 17
  • 26
  • Thanks for your reply. But as I pointed out in my question, I don't have any activity in my library. Only a custom view. I'd like to start an activity from it but how can i do that without having this new activity to run on top of the activity of application using my lib? – eFyx Oct 26 '11 at 19:44
  • @eFyx - Have you tried implementing this as a service or is that not applicable for your situation? – Carth Oct 26 '11 at 19:52
  • No it's not applicable for my situation. – eFyx Oct 26 '11 at 20:28