I have an application with one parent and some child activities. Requirement is to play some custom animation on child activity launch. For smooth animation and avoid delay between switching I applied Theme.Translucent on application in the Manifest. Animation is running properly and application behavior is proper until I turn developer setting ON to keep single activity.
Application stuck at the parent activity due to infinite recreation (onCreate() followed by onStart(), onResume(), onDestroy and so on) when there.
1) Developer setting is ON to keep single activity.
2) My application goes in the background with child activity is on the top.
3) My activity comes to the foreground.
I am facing this issue only on Android 4.0 series but found in the documentation that Theme Translucent is for API Level 10 and below.
I think activity recreation issue is due to translucency of child activity that is on the top and parent is below. As child activity is translucent, its require parent activity in the background. App creating parent in background and its being destroyed due to developer setting is ON.
I tried to find Translucent equal for API level above 10 but no luck. Is there any API to Translucent activities with API level above 10 or any other way to avoid flickering/delay between activity switching.
Thanks
If you want your activity to have a translucent window, you can add:
<item name="android:windowIsTranslucent">true</item>
To your AppTheme in res/values/styles.xml.
Related
I'm trying to look for any Android Element or Window which will stay on top of the app and will not be removed when changing activities.
Android's banner seems to be per activity.
PopupWindow as well.
I can't change the app's activities - cannot change them into fragments.
Is this possible?
I'm trying to use AnimatedVectorDrawable as a splash animation placed in the window background. I use the official example given in https://developer.android.com/reference/android/graphics/drawable/AnimatedVectorDrawable.html. It appears but doesn't animate.
Are animations in a Window background possible at all?
The first screen that you see when opening an app for the first time (cold start) is a screen placeholder create by the WindowManager. It creates the placeholder by getting resources that you set on your theme, like the window background and status bar color. To start the animation of your window background you have to call its start() method, but the WindowManager is a system service that you have little or no control over. So on this phase of application initialisation, unless there is some obscure way to control the WindowManager in the Application.onCreate() method, it is not possible to animate the vector background.
I opened from cold start a lot of my apps including Google ones and not a single one seems to implement animations on the cold start phase (like the docs of Material Design imply possible). A very few make animations after the cold start at the onCreate of the main activity.
If it's not a problem start the animation after he cold start, like in the case of moving the logo to the top of the screen, you can:
Set a theme with attribute android:windowBackground to your static drawable at your launch activity in AndroidManifest.xml
Before call super.onCreate() in your Activity, change the theme for your default theme.
Set a content view with a ImageView of your AnimatedVectorDrawable at the same position of your static window background vector.
Call start() method of your AnimatedVectorDrawable.
Here is an AndroidDeveloper's post explaining in details how to deal with application themes for launch screens
I'm trying to set the theme of my Activity during runtime, choosing one of a number of themes. I want the chosen theme to display immediately on startup of the Activity.
In the <application> part of my manifest I have set a default theme with android:theme="#style/AppTheme". And then in my onCreate() I use setTheme(R.style.DarkAppTheme) to set the theme to a user-selected theme (replacing DarkAppTheme with the selected theme).
And based on research it seems that setTheme() should go before onCreate() and before setContentView(), which I do.
BUT although this works to display the Activity in the user selected theme, the Activity first loads with what looks like the default theme, and then after a short delay the correct theme loads.
If I set the user selected theme directly in the manifest, that loads immediately as I want, but of course that is hardcoded and I want to change this dynamically based on a shared preference.
How do I avoid the visible changeover? I want the user selected theme to be displayed right from the start.
Thanks.
The Activity first loads with what looks like the default theme, and then after a short delay the correct theme loads... How do I avoid the visible changeover?
There are 2 parts to an Activity 'Enter/Opening' window animation, when your app is first launched from the icon on the Home Screen:
The 'dark gray rectangle appear' animation. This is the initial blank screen that the system process draws when launching the app (source). It's also known as the "theme preview" screen or "splash screen". It can be white if your app uses a Light theme.
The 'fade in (or circular reveal) of the view layout'. This is the animation of your view layout appearing on top of the dark gray rectangle. It happens after part 1.
Part 1 is what you identified as "what looks like the default theme". You can disable this first part with the following item in your Activity/App style:
<item name="android:windowDisablePreview">true</item>
This will prevent the 'dark gray rectangle appear' animation, and only allow the 'reveal of the view layout', to therefore avoid the visible changeover or flicker. But there are caveats:
You have to ensure that your Activity launches quickly, because there will be no visual animation feedback for the user until your layout is fully loaded. That's why the theme preview is normally on by default.
It causes strange bugs on context menus: For any PopupWindow, the 'Enter' animation will no longer happen, and it will just display instantly ('Exit' animations are not affected). This also applies to system PopupWindows like the overflow menu list, and the drop-down list of an AutoCompleteTextView. This bug happens on Android 4/5/6, but not on Android 7/8. More info here.
Documentation of windowDisablePreview:
Flag allowing you to disable the splash screen for a window. The default value is false; if set to true, the system can never use the window's theme to show a splash screen preview before your actual instance is shown to the user.
Further info:
How to set a theme to whole application in code, but not in the Manifest?
Android - Disable dummy starting window of application
The theme on AndroidManifest just appears if your Activity take too long to load. You can try to tunning up Activity load and remove android:theme="#style/AppTheme" from AndroidManifest or even set a compromise between these two use.
I hope it helps you \o/
In my application i am using a splash screen for the application start up with the theme #android:style/Theme.Black.NoTitleBar.Fullscreen.
After 2 seconds the app goes on to the main activity which uses this theme: #style/Theme.Sherlock.Light.DarkActionBar.
One is in full screen, the other one is not. The transition between both is not smooth and it takes a while (~1 seconds) for the main activity to adjust to the status bar. Is there some trick to avoid this?
As far as I know, there is no api level solution for this. I suggest Using TransitionDrawable for example changing background color and/or PropertyAimation for changing view's properties like background color or text color. Then you can call setTheme() function of activity to apply your new theme. be careful that setTheme() must be called in onCreate() function before setContentView.
I'm trying to implement tab buttons bar and a navigation bar in my android application. The problem is, that I would like the navigation elements to persist. When starting a child activity, the nav bar moves.
How can I make these two elements "non-movable"?
Add button bar and navigation bar to all your activities and share it's state via static fields. Remember to initialize bars when child activity starts and update parent's bars when child activity finishes (either via onResume or as a result of startActivityForResult).
It is not possible to share instances of UI elements between activities, as Activities are (by design) independent of each other.
Application cannot control how new activity is introduced - it can slide, zoom in or just show up if user disable animation in device preferences, UPDATE: it looks like since API Level 5 there are ways to override this, please refer to Activity transition in Android . But if you really need to keep bars in place, use single Activity and replace main view content with animation you like.