Android: backbutton animation when orientation is changed - android

I have a rather weird problem. Everything is working as it should except for this little thing. I'll show the code.
// ...lots of other code
ft.setCustomAnimations(R.animator.slide_in_right, R.animator.slide_out_left, R.animator.slide_in_right, R.animator.slide_out_left);
ft.addToBackStack(null);
// ... some more code
It's pretty simple, when I click a button that replaces a fragment with another fragment an animation between the two is played out. This works dandy! And as you see, the same animation is presented when I press the back button.
It all works! Until... I change orientation. Let's say I'm at the third fragment, change orientation and press the back button, the animation does not play out. The previous fragment is displayed instantly. When I click a menu button again to the third fragment the animations all of a sudden start to work again.
I'm guessing this has something to do with the Bundle, as when you change orientation the Activity is stopped, then started and the savedInstance being "reinserted". However the savedInstance animation was made for portrait and not landscape. Or it's simply just not saving the setCustomAnimations().
Is this a bug or is this how it is supposed to be?

As far as I know, this is a reported bug both in the native and support libraries.
Look at this question, or here for some advices. I tried the last advice in the second link and it works fine now.

Related

Activity is destroyed when hit home button (only on Pixel3)

I have one big and long question
I have one activity with 4 fragments using viewPager.
the first fragment also has 4 fragments using viewPager
the second fragment has 6 fragments using general fragment way (replace or add on framelayout)
Here are my question and problem
For example, I am in the first tab and in the second fragments, then hit homebutton and then bring my app upfront. after that suddenly all functionalities are not working. the back button is not working. the button in the fragment is not working. (error log said the fragment is not attatched)
it happens only on pixel3.
I have 5 different android phones but working fine on those phones.
I thought it could be the memory issue, so I turned on "profiler" from Android Studio, and I saw the weird thing. only pixel3 when I pressed the home button the activity is destroyed. I tested all other phones with "Profiler" the activity's state is saved not destroyed.
Does anyone have the idea of why it happened and fixed the problem?
Are the embedded fragments problem? or is it OS10 problem?
I found the issue. there is one option in developer mode named "Don't keep activities". that was on, that is why my app is working differently on pixel3.

Android - Adding VideoView to a fragment

I'm experiencing a strange problem. I have an app, based on fragments. When I want to change fragments, I first check if the fragment is added. After hiding the previous fragment, if the next fragment is already added before, I just show it. If it is not added before, then I add it. And one of my fragments has a VideoView declared in it's XML file.
Now my problem is, if the fragment is not added already, when I try to add it, the whole screen goes black for a second and then comes back with the new fragment. The portion that I am placing the fragment is only a part of the screen, so it should only refresh that portion of the screen. After the fragment is added, when I try to navigate to it (when I use show() method), I do not experience this behaviour. I believe this has something to do with the VideoView, because if I remove it from XML, I no longer experience this problem. I tried adding the VideoView programmatically, but I still had the problem. I also tried to use a SurfaceView to play the video, but in that case, again I have the same problem.
I would appreciate any suggestions. Thank you.

Facing issue with setCustomAnimations() while replacing fragments

I have 2 fragments A and B. I am replacing the fragment B with A, and setting setCustomAnimations(right_to_left, fadein, fadeout, left_to_right). Fragment B is behaving correctly like it is coming from right to left and on pressing Back button and do pop back stack it is leaving from left to right. But no animation happens to the fragment A its doesn't fade in and fade out.
Note: I have tried it with creating the sample application and it works perfectly fine but when I implement the same thing into my project it behaves as above. What mistake am I making while implementing the setCustomAnimation() in the my project?
I have already tried:
have a latest support library
hardwareAccelarated="true" in the manifest file
add setCustomAnimation() before replace() method
compile it with above 3.0
I doubt there can be an issue with the framework my app is built on but not sure. Can anyone please let me know what else I can check to make it work?

Android Ghost Layout on Activity Transition

I noticed something strange today and i'm not sure the best way to describe it.
I have two activities (A and B). I'm on A and start a new intent for B. I override the pending transition to be a slow slide up. This part is fine.
When B is sliding up I noticed that I can still tap on the screen where B's buttons would be and use their actions. (example, there is a close button to close B. When I tap on it's destination area it will close B even though it hasn't completely gone up).
My current solution is to disable all of the buttons until the animation is done. This is working fine, however I'd be interested to know if there is a better (more standard) solution. If anyone can explain (and confirm my suspicions) then that'd be a nice plus!
This is the expected behavior. Android is simply animating a transition and not actually moving the views from one physical location to another.

Menu does not showup first time after install

i a facing very weird problem in my app. i am inflating a layout on pressing menu key. and setting that layout on popupwindow. the prob i am facing is that when i install build on device and press menu key, popup does not show up. but if i navigate to some other screen and come back to previous screen, menu key works perfectly.
even if i cllose app and open it next time, menu key works fine. it does not work for the first time after install.
thanks in advance.
Maybe you set your click listener for the menu button in the wrong lifecycle method? Perhaps it doesn't add the listener until after onPause()? Seeing some source would be very helpful to be sure.
I think android pretty much decides on its own when it updates its layouts and redraws the view. Maybe your newly inflated view doesnt affect the other layouts in a way that makes this seem neccessary. I would try to call requestLayout()/forceLayout() on the main layout...
Not sure though...

Categories

Resources