Calling setContentView for animation - android

In my application we are achieving the page-animation by using setContentView every time the animation occurs. The layout contains just an image so its definitely not too heavy. But are there any other problems in calling setContentView again and again on the same activity. Will it cause memory leaks or something similar.
Tried searching the net but since our layouts contain only the imageviews the onSaveInstance also doesn't have much to do.
Let me know your inputs.
PS I know about ViewFlippers and other waqys of animation. Was just curious if its advisable not to call setContentView in an activity repeatedly and Why?
And I can't create a tag for setContentView if any of you can please tag this question with that tag.

Related

Best method to execute method before layout is made

I've a method createLayout(); (simple fragment) . Before I create layout I want to remove one fragment off the stack using popBackStackImmediate();. Problem is, that popBackStackImmediate(); executes a lot slower than createLayout(); which leaves me to creating layout alot faster than I need to. What are the best possible solution here? I would like to build layout only when popBackStackImmediate(); is finished. What are the best solutions for this case?

Android - add a view that will exist despite setContentView()

Anytime one calls setContentView() multiple times, previous views get destroyed. How does one create a view that will exist, as an overlay or under the main window, despite multiple calls to setContentView()?
OK, I think I'll answer myself: After some reading I believe I shouldn't be calling setContentView multiple times.
Instead I should use one layout that has the view I wanted to exist despite layout changes and also put ViewFlipper and use that for layout changes not setContentView.

Creating/Rendering Activity before starting it

We use different activities to navigate through our app. One of them is very complex and contains a lot of nested views/images etc, so when I usestartActivity(intent1) in the activity before it, there is a short delay and it feels/looks laggy.
All the information needed to create the content views is known in advance.
So my question is: is there a smart way to prerender/preload the activity or its content view?
As i figured the intend only holds information about the next activity but no instance of the activity itself, so i assume there is no way to tell the intend to create the activity before i call the startMethod.
One idea i hat was to create a static view before starting the activity and set this view as contentView in the onCreate() method. But it seems like a bad hack to me.
Thanks in advance!
The best solution would be not to start a completely new activity but using a ViewPager or ViewFlipper. Switching between Views should be then nearly instantaneous and you also get the chance to easily apply animations.
If that is not possible you could start a new activity but put a ViewSwitcher in there. The first View would be a progress bar. The second view is inflated and added to the Switcher in a background thread.

What comes between onCreate and onStart for Android?

I see from Android Developers (http://developer.android.com/reference/android/app/Activity.html) that there is a nice flowchart showing onCreate leading to onStart then to onResume, and so forth. My question is: what other on****() methods appear in between onCreate and onStart?
For example, I've been doing research on the topic, and I know other methods such as onMeasure and onSizeChanged, onDraw, and others exists. Where do they fit in to that flow chart?
Thank you.
The methods you mentioned aren't related to the Activity lifecycle.
For instance, it would be incorrect to include the call to onMeasure in the Activity lifecycle flow chart. onMeasure is called whenever the layout changes (i.e. when requestLayout is called) or the first time a window is laid out. The call to onMeasure isn't directly related to the system's calls to onCreate and onStart.
Those other methods exist, but they don't really fit in any one place on that flowchart, nor are they part of the activity lifecycle. in fact, that's why they're not on the chart. The ones you mentioned are really more of the view lifecycle which is separate from (though admittedly related to) the activity lifecycle.
This image can clearly depict what you want.

Android animate to singleTask

I am making an app with multiple tabs (without the tabview). One takes a long time to load so I made a singletask of it. Now it only has to load once what saves a lot of time.
Only in the onCreate I define the transition I want:
overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
Only the onCreate is never called again, i tried to put it on top of the onResume and onStart but that didn't helped either.
The problem now is that the animation becomes the default animation which differs a lot on different devices.
Does anyone know a way to change this? I tried calling it after the startActivity method with no succes either.
If anyone has a solution to stop the loadtime then it is also okey.
The load time goes to making multiple listview in a swipeview (jason fry). This listview contains around 90 imageviews each, most of them are the same image.
Thanks for any thoughts, ideas or solutions in advance.
You should override the finish() method of your activity.
In the overridden method, after calling super.finish() - call overridePendingTransition() with your favorite transition (if you want no transition - define a transition that does nothing, with duration 0).
You could try calling that in the onNewIntent() method. That should be called when you try to launch the Activity a second time.

Categories

Resources