Android restore animation on activity resume - android

I have an activity where i do a scale animation on a view when a button is clicked.
I have set fillAfter as true for the animation.
When the animation is done, I start another activity. The problem is when I go back to my original activity, my scaled view is back to its original size.
Is there anyway to leave the activities content view the way it is when we start another activity?
I read the saveInstanceState, but most posts over here refer to saving values and not the UI. Im not really sure how to tackle this issue in a efficient way.
Or should I save the scaled view and restore it on the onResume function of the activity?

I was able to solve this issue by adding the launchMode attribute in the manifest file.

Related

How does one save the current view in android?

The design of the application that I'm working on is fairly simple so I've decided to use Activity.setContentView() to switch between the few different layouts it has. This all happens within a single Activity, of course.
To explain it better - let's say that I have a main layout with a simple navigation and a settings button.
The problem is that whenever I show the settings view upon click and later try to set the main view back, it is unusable. It just loads the main layout, but no listeners are set, as if I show a picture.
I've figured out that I should use the setContentView(View view) constructor instead of the one that passes the layout id from the resources. Though, I have no idea how to save the current view..
How to save the current view with all its listeners and stuff to then pass it to the constructor and save my data?

Can you measure the height of a view on an activity that's not been loaded yet?

I want to make an animation on click that a button slides down to the position of another button and at the same time I'm loading another activity. This other button is on the new activity. Picture it as if a button from one activity is replacing a button on another activity, so it has to slide down to where the new button is.
Can I measure this new button's position before the activity is loaded? So I can get the animation right for all screen sizes.
Activities are designed to be used as full-screen components, meaning that you understand that the other activity that pops in is going to take the full screen. If that is your goal, you can use shared element transitions with the activities to get the desired effect: https://developer.android.com/training/transitions/start-activity#start-transition
On the other hand, if you need both activities to stay on the screen, than you should rather to use fragments, as activities are not suited for that. For more info on that approach, see here: https://developer.android.com/guide/navigation/navigation-animate-transitions

Android Change Different Layout

I have a TabHost set up with tabcontent. However, this tabcontent doesn't take up the entire screen and a different layout is loaded at the top. How can I change the image in the layout above from within the on create of a tab activity?
Thanks,
You will not be able to access Activity A's view from Activity B; this is because it's very possible that the view will be destroyed when you launch Activity B.
What you can do however is somehow let Activity A know to change the ImageView when you come back. For example, you can have a static field or you can use setResult().
I see Three ways:
1.Share the ImageView between two activities. To do that, you can put this element as private and create a getter. Then, you just have to access this element and change the element. I'm not sure that will work.
2.preferred way
Load your image in onResume from a remote source. Then, you juste have to change this remote path from your second activity.
3.previous response

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.

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