I have an app which has an activity A, that lets the user click on a thumbnail and go to another activity B which shows the thumbnail full screen. On activity B, if the user clicks anywhere on the screen, it closes the activity.
Both activities are defined as portrait in the manifest, and both have the onConfigChange value to contain the orientation flag.
It works perfectly on all versions of Android and all devices that I've tested, except one - Motorola Xoom, with Android 3.1. On the Xoom, if the user navigates quickly between the activities (back and forth), it has a chance to show activity A in landscape mode for a very short time, as if it planned to switch to it.
Not only that, but if it remove the flag of the onConfigChange in the manifest, activity A might re-create itself from scratch on this special case.
What could cause this weird thing? Is it some weird bug on android 3.1 or the Xoom? Is there anyway i can fix this issue? I could have something that blocks the touch on activity B for a few ms on the beginning, but that's just a workaround.
Related
I just come into a very weird situation today which is when I use a tablet AVD device, my main activity starts with an old design which I want to change, but when I try changing anything in the UI nothing changes in runtime and android still loads that old activity design.
This happened when I created two activities; the main one for small screens and another with sw-600dp, then changed my mind that I want to change the design for tablets ONLY when they are in landscape orientation. So, I deleted sw-600dp activity and created an activity-land, but the tablet had stuck with the old one and does not change anymore.
I tried deleting the whole main activities to see what happens, however, the app still opens normally with that old activity. I also tried to search for that stuck main activity, maybe it is hidden, but didn't find anything. The strange thing that my code is referencing the activity normally EVEN after I deleted it entirely. Moreover, tried to right click on this reference and go to declaration but it didn't open anything.
Note: when I try another device that is not a tablet it acts as expected that there is not activity and app crashes as expected so there are no problems with these small screen devices.
Here is a screenshot of my activities and how my java code is still - weirdly - referencing an activity that does not exist!
I want to test the state of my app when it's left in the backstack for too long.
When I open like 20 apps one after the other my last used app (which is the app I'm testing) eventually terminates and a savedInstanceState occurs. Is there a way to simulate this behaviour for the app I'm testing without having to open another 20 apps in order to burry my app in backstack?
Yes, there's a simple way to do it. Just enable Do not keep activities under Developer options. Your activity will then be immediately destroyed as soon you leave it and onRestoreInstanceState() will be invoked when you return.
Alternatively, you can force a configuration change (like orientation) and that will recreate your activity too. One issue with this approach is that there's a bug with some JellyBean/KitKat versions where the emulators fail to rotate. (This works fine on a device though.)
The workaround is to install the RotateScreenOrientation.apk which can force the emulator to be in portrait or landscape but this quickly becomes tedious if you have the option to Wipe user data on emulator start enabled.
So I'm making an app for my company, for a android tablet to be used like a "kiosk". Users should only be able to use this one app, and be able to do nothing else on the tablet.
I've found a solution by using WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED on the activities. However, when I switch to another activity in my app, the leaving activity fades out, shows the lock screen quickly and then the next activity appears.
I'm guessing that this is because the FLAG_SHOW_WHEN_LOCKED is in onCreate(), as opposed to earlier in the Activity creation process.
Is there anywhere else I can put this flag, or any other way to prevent the lockscreen to be shown between activities? It's not a huge issue, but it is a poor user experience.
It is a Samsung Galaxy Tab 10.1 Running ICS 4.0.3.
I was able to best fix this by using Fragments and using FragmentManager to swap out the fragments in the activity, so the lockscreen was never shown, since I never left the activity. The android developer guide has a good example for this.
http://developer.android.com/reference/android/app/Fragment.html
I developed a pretty simple game that uses a custom view for drawing to the screen. On my phone (Android 2.2), I can press the home button on the device and do other tasks. When returning to the game, it is restored to the exact state that it was before. The thing is, I didn't have to override any methods or really do anything for this behavior to occur. However, on Honeycomb, it resets everything like I would expect.
It's very puzzling... I was wondering if there was a way to make Honeycomb behave like 2.2 in this regard. I'm not too familiar with saving view states, but since I have a LOT of variables (hundreds, depending on how custom objects are saved), I imagine it being unpleasant to manually do.
I was able to solve it. Kind of.
Basically, the problem was caused by the way that Android handles the screen being fixed to portrait mode in my activity. In 2.2, Android would open the activity in portrait mode and not restart the activity. However, in Android 3.0, it opens the activity, and THEN rotates the screen, causing it to restart the activity (since that happens when a rotate happens).
To fix this, I added the following to my activity in the manifest:
android:configChanges="keyboardHidden|orientation"
This tells Android that you will handle config changes yourself. In my case, I do nothing, since my application is locked in portrait mode.
The reason the state isn't cleared when the application is paused is because onCreate() doesn't get called. I am aware that Android can kill the application though, which would call onCreate(), so I will still have to handle that situation by saving the Activity variables and recreating the View with them.
While testing on Android 1.6 using a G1 I have noticed that when I slide out the keyboard it kills the activity and recreates it even though I have set my activity to only display in portrait mode.
Same happens when I push the keyboard back in.
I get onSaveInstance, onDestroy called, then onCreate, onResume, OnrestoreInstance...
I understand why this is done when the display is being switched to landscape view but why does this happen when I specifically dont want my activity to switch view, its essentially killing and restarting the activity for no reason.
Is it the same on 2.x devices?
Is there something I'm missing to stop it happening?
Can anyone explain if there is any point to it?
This is the recommended behavior in Android. But if you want to stop this you can specify the following property in your Manifest against your Activity
android:configChanges="keyboardHidden|orientation"