To handle orientation changes, im overriding:
onConfigurationChanged
But regardless of where I make the call to
super.onConfigurationChanged(config);
The super always gets executed AFTER my code
Is it possible to have code be executed after the super, which is after its rotated?
Edit: I guess there's no way around this. It seems that when you override a function, the super gets executed last no matter what.
set a break point on your super.onConfiguratioNChanged, I highly doubt that "regardless of where [you] put the call" it still calls it last.
Related
I have inherited some code hence I don't have true freedom to change it. :(
I have a main activity, from which other activities (I will refer to these as sub activities from now on) are called. Whenever one of these completes, it calls finish and returns data to the main activity.
Each activity (including the main one) has a bar on the top that displays a custom view. The custom view contains a canvas which has a drawing that is dependant upon the state of the network.. i.e. wifi/mobile etc...
Since that 'state' data never changes, it's held within a singleton and the view gets data from the singleton to define what it draws. That is working with no issues, i.e. the data is always as I expect it.
When I first launch the MainActivity, as the network changes, the data changes and each call to 'invalidate' the view receives a system call to 'onDraw' as I would expect.
In each of the sub activities the same is again true.
Upon finishing a sub activity and returning to the mainActivity, calls to invalidate no longer cause a call to onDraw to occur.
I have looked at this for quite a while now and just cannot figure out what is going wrong.
In my constructor I have:
setWillNotDraw(false);
Whenever the data changes the following methods are called:
invalidate();
requestLayout();
Now, there's one more thing... upon returning to the activity at that immediate point, I refresh and this DOES draw correctly, i.e. invalidate does trigger an onDraw call... any subsequent network changes (which are propogated) fail to result in the onDraw call.
I'm wondering if this is to do with the view somehow being detached. I can see that 'onDetachedFromWindow' is called, however the trigger for this is the destruction of the subactivity, hence I don't see why that should affect the MainActivity but it's the only thing I can think of.
I'm hoping I've provided enough information for someone to help me...
Well, in the end my answer has very little to do with the question and I guess this is an example of how an issue can be solved by going back to absolute basics and checking for the obvious.
My activities all inherit from an abstract activity. Within that activity there is an instance of the view. The views in which I was having trouble were using that declaration as opposed to having their own instance, hence behaviour from one activity was then affecting another inadvertently.
So, if I'd been able to post up all the code, I'm sure someone else would have spotted this but, unfortunately I couldn't in this instance.
Still, whilst this posting doesn't provide a resolution that will help others, maybe it does say... step back and check the obvious first!
I want to execute some code before process screen rotation.
But I don't want to override onConfigurationChanged method because I want to use system to perform rotation.
I have to use a "clean way" to perform that.
I'm a clear ?
Thanks.
If you override the method but still call super.onConfigurationChanged(conf) you're essentially extending it's functionality, meaning you can execute your code and still get the rotation or whatever the method normally does.
That's as clean as it gets
I'm trying to get the result from getLocationOnScreen() as early as possible.
However, putting it in the onCreate() event I'll get 0 as my results (which I suspect is because the Window has not been fully created). onResume() also does not work unless the application has been brought to background and then front again (i.e. it works on the second call of onResume()).
Where should I put getLocationOnScreen() so I can get the results early; or maybe is there a way to force getLocationOnScreen() to work even before the Window is fully created?
Thanks.
The activity lifecycle is
onCreate
onStart
onResume
//app is running
onPause
onStop
onDestroy
All of which you can override
http://developer.android.com/guide/topics/fundamentals/activities.html#ImplementingLifecycleCallbacks
In my app I needed to call findViewbyId() from both onCreate() and from WebChromeClient.onCompletion(). To avoid findViewbyId() returning null I resorted to calling Activity.setContentView(int viewResID) before calling findViewbyId().
It works, but now I am wondering whether I may have created a "time-bomb" in my code down the road.
Are there any caveats that I need to keep in mind when doing something like this?
There is no problem in doing so. You have to reinitialize references (every findViewById needs to be called again) and it might be troublesome if you do it A LOT of times, but it is not a time bomb at all.
Am I forced to use the notifyChange() method? I ask this because, when I call this method it enters on the onChange() method, but when I don't call the notifyChange() the onChange() method is not called. Why?
Okay here goes,
I don't know if this is a complete answer to your question but anything that inherits from the abstract class ContentObserver should call its "onChange" on instantiation. With that in mind take a look at the ContentObserver you are passing to your notifyChange. To start with I'd say debug step by step with that much in mind and tell me what you get...
But based on the source code, It looks as though ContentObserver fires the OnChange and that "bubbles up" through the the notifyChange method.
So with that the best sense I can make of it is that since the point of the ContentObserver is to "Observe" or listen for the firing of events (aka intents i think; I'm still trying to get the android lingo) then if you want your Observer to know your onChange is happening then yeah. But I think I would need more information about how your going about using it to give you a clearer explanation.
And by all means someone please set me straight if I'm at all wrong here in what I said lol.