I have an animation for my splash screen and on some phones which take longer to load things, it starts mid animation.
The splash screen is really an activity that has a View, in which the animation is drawn. Is it possible to wait for the screen to load and then start the thread in the View? I mean can I somehow check if I can begin the animation and it will be shown, the whole thing
Do yourself a favor and DON'T use a splash screen. On Android guidelines Google is extremely against splash screens because they give some sort of slowish UI perception to the user, and it's not a good thing at all.
If you absolutely need to wait for some sort of data to finish loading/network query you can do it much more elegantly by letting the app load normally and give the user a loading indicator (e.g. SwipeToRefreshLayout from the v7 support lib).
Not actually answering your question but this is a much more elegant solution for a completely wrong approach for a good UX. The Animation.AnimationListener has a callback called onAnimationEnd where you can do whatever after the animation has finished.
Related
I have an ImageView. When user presses button I want to change image (it is animation-list) and run this animation. I used to use setImageResource, but it blocks UI thread and causes lags. I can't predict what image I would set befor user presses button. I tried to preload drawables but it causes OOM, because I have about 30 xmls with animation-list. How can I solve It? To sum up, I want to fastly change image in my ImageView and then start frame animation on it.
I think you are performing a fetch operation on the UI thread for the image(either from storage or network call). That is what is causing the lag.
You might look into using a library to load up your images. There is one that is really easy to implement called Picasso. It's been around for a while too, so it should be easy to see some examples.
I am trying to make an App which is going to display Some Images and Videos. So I am planning to add a splash screen of around 2seconds. After 2 seconds the user will be taken to the Main Screen of the App.
I want to start the loading of the Images, Video when then user is at the splash screen itself so that the user should wait for the least time when he is at the Main Screen.
So the loading will be started at the Splash Screen and then after two second the user will be taken to main screen irrespective of the completion of the loading.
Now since this involves two activities should I use a Async task or should I Use a service with an Async Task(For the callback of completion of code) within it?
Which one would be better. Also in Android 8.0 are there any restriction in using Services?
I think using a Async Task between two screens may cause Memory leak if not coded properly.
Any help would be really grateful.
EDIT: My app is having one more feature hence cannot make the user wait in the Splash Screen till the loading is over.
It is not very good to use AsyncTask for sharing results between 2 activities, because AsyncTack created in Splash activity will be destoyed (stopped) when switched to Main activity. Better to use service in this case and Main screen will subscribe for result.
So basically you want to start the download in the splash screen and continue the download in the activity that follows. In this way, you still have to implement a loading animation. In your case, I would recommend finishing your splash screen, as soon as everything is downloaded. In that way, you don't have to download anything anymore inside the app's lifecycle.
AsyncTasks continue to run even after switching to a new activity. You can try the following flow:
1. Splash screen
2. Trigger Async Task
3. Main Activity
4. Show Images/Videos
The only catch is, you will not be able to fix a time for #2 to complete to be able to start #4. This is the nature of AsyncTasks. You can workaround by using the OnPostExecute within AsyncTask.
Example: OnPostExecute call another method that will enable a button. Users can click on the button to view Images/Videos. But then, this might not be a good user experience to see some button suddenly getting enabled.
In that case I would rather create some Singleton with own Handler (that works in separate Thread), that will be started at Splash screen. After Main screen will start, it should ask that Singleton about respective data or should sign himself for receiving that data.
My question is about how to make splash screen, and finish the splash screen if the MainActivity done rendered, not by timeout set.
I have been searched how to make splash screen and i have done it, but mainly they are using timeout to set when the splash screen have to closed/finish.
What i want is how to finish the splash screen when the MainActivity completely rendered, not after how many seconds to close the splash screen.
Is there any way to get something like render completed state?
I tried to code the finishSplashScreen() in the onResume() and worked as i want, but the problem is, its always trigger the finishSplashScreen() when you reopenning the MainActivity whereas i just want to trigger that function only one time when the app is openned.
Is there any way to make what i want?
Update
I found what i need, this tricks simply useful.
http://saulmm.github.io/avoding-android-cold-starts
I have been searched how to make splash screen and i have done it, but mainly they are using timeout to set when the splash screen have to closed/finish.
Then you probably have not done it right.
Hard to tell without seeing your code obviously, however this link can most likely provide you guidance on how to build a proper SplashScreen :
https://medium.com/#ssaurel/create-a-splash-screen-on-android-the-right-way-93d6fb444857
No timeout, just a very fast-loading SplashScreen (no setContentView, only theming), and the only responsibility of this SplashScreen being to launch your MainActivity.
Hope that helps.
I wrote a fade in fade out method for views. It works perfectly, but, as I understand, each view's animation is handled by a separate thread in the background, tackled by the android system.
That is a problem, because, I want to blink and the same pace.
Is it possible to do that? I tried to put my blinking method in a runnable and restart it every time a new View starts its animation, but it is not working because 1. you cannot simply restart a thread, 2. even if you can, the Animation will be handled by the system with different threads each running independently anyway.
How should I do this?
Let me narrate my goal again: I tap on a view, it starts blinking, fade in fade out style, using a method I wrote. Then I tap on another, both blinking at the same pace, with the first one perhaps noticeably changes its original blinking pace to be in sync with the 2nd one. Then I tap on another, another... no matter how many I enable blinking animation on, these views all fade in and fade out at the same pace.
Can you offer any advice? Either a specific one or a general one.
I'm currently in the process of making one of my first android games and have come into some difficulty understanding how to make the transitions between screens.. for example:
My game starts its main activity, which then loads TitleScreen surface view which initializes its own thread
on tap I start a new intent which loads a new activity which loads GameView surface view which initializes its own thread
This all works fine when testing on my device (Evo 3d) but crashes on tap on my test bed, I'm using android x86 in virtual box for quick testing. Is this likely to be a problem in my code or a problem with the simulator?
Also I'm wanting to add a level select screen in between the title screen and the game screen and figured i could do this by creating another activity/surface view/thread combo, Is this acceptable coding practice or is this a wasteful/process heavy method?
You could create a variety of methods that you call from your onDraw method. Each method would draw one screen (game, level, score). To start simple a switch case in the onDraw checks the screen and then calls the right thing to draw.
If you want to have different layers, you should use different acitvities so that the background (game) is being paused while the scoreboard is active. This only makes sense if you want the background to be still visible or need the acitivites for other reasons.
But you should never have more than one surface view active at the same time, android doesnt like that.
I think its not good to use more activities for single application. Try to use ViewFlipper with number of xml layout files. Here you can apply transition effects very easily.
I am suggesting you it for transition effects, but you also check it once. I am also thinking which one is good.