I have code that reloads images via HTTP from the main thread and displays them, right after setting up the layout.
This is now deprecated since network access must no longer be done from the main thread.
At first, I changed it to load the images from a a background thread and then update the ImageViews. But, the user experience changed since the images now "pop out."
Is it possible to make the images load seamlessly?
Or, should I display a progress bar or status message while the images reload.
Seamless loading would require to delay to display your entire ui which is probably not what you want. You could use an animation to fade in your images once they are loaded.
Related
This question already has an answer here:
How can I display a Progress at start up application in android
(1 answer)
Closed 5 years ago.
I have a heavy user interface that can delay the application load. I want to show an preloader before the UI of activity loaded. note that my ui is in xml file
EDIT:
If you want to load 10 tabs in a view pager, use a FragmentStatePagerAdapter which only loads neighboring tabs(default behavior).
If the heavy UI you specify is only the UI elements, then the app must freeze while loading it. So you'd better show a non-cancelable dialog(without animation) with loading message and after a few moment (like 200ms) load up your UI and explicitly dismiss the dialog.
But if the heavy stuffs is not just UI, maybe some calculations or image processing, just do it in a background thread while showing a dialog with progress and cancel the dialog when the task is done.
#Hassan according to me if on clicking the launcher icon if it takes sometime for your application to render the first screen(perhaps giving a black screen in between). This needs to be corrected in your application.
On the contrary if your applications main screen requires population/retrieval of certain resources for effectively engaging the users, You can possibly do something like a splash screen(outdated) where you do all "population/retrieval" and then simply pass data to your heavy UI.
Now regarding the progress bar if this fetching of data is small, you can give an indeterminate "custom"(some moving animation that would suite your app) progress bar,else if its something like a download you can easily track its progress and show in a horizontal progressbar
You sure can! You are describing a preloader. Here is a nice example of one https://github.com/rtheunissen/md-preloader
You'll have to add more info to your question to get a specific answer, but there are a few basic principles.
You make your life a lot easier if you use a preloader which doesn't show progress of the load, it just goes round and round, because the speed of some load processes can't be measured.
If its a data-load which is taking the time (such as a call to an API), you might want to set a variable for "loading" to true at the top of your script, then when the data has resolved, set it to "false". In your view, have a state or a conditional element which hides / unhides the preloader.
If lots of images are slowing down the page, you might want to look into "lazy-loading" or using "infinite scroll" to only show content when the UI needs to display it on screen.
Thats all the info I can give without more information on the code you have so far. Hope that helps!
I have a layout in my app that has lots of images, buttons and other layout elements.
The first time the user starts the activity of that layout, it causes the app to freeze for 1 second.
I want to load the heavy layout elements in my splash screen, so that when the user starts that for the first time there is no freezing.
How could I go about adding this feature into my app?
First load all the UI elements and then try to load the images in your respective layout.
Loading the images can be long process, so use async task for that.
For loading the images efficiently you can use the following code shared by Google. Below is the link for that...
http://developer.android.com/training/displaying-bitmaps/load-bitmap.html
You should probably look into AsyncTask Handler. It will also allow you to easily support progressbar.
In case if you have a lot of images to load, you can use image loading libraries refer this link for more Image Loading Library. These libraries load images in background and provides many more options to deal with images.
i have created a android app it works fine and I am loading my UI that contains a scroll tab with several fragments, the UI in the main activity takes 4-6 seconds to load and only a blank white screen is seen till then, how can I show a progressbar till that UI has finished loading there s no data to load just the UI so please dont tell about asynctasks
You will have to first display a simple activity with your progress bar and then start to add the parts of your ui in background one by one to the activity by using an async task.
If you are using commands that can only be performed by the ui thread you have to post them to a view or a handler from your async task.
Ensure that the different blocks you are loading are not taking too long to give the ui thread time to update your progress bar in between.
I know you don't want to use an Async task but that would be the best solution. Start an async task loading the UI (Can use existing class) and read a true false (indicating when done) value from onProgressUpdate(), which can be accessed from the UI thread. Display a spinner while false. Hope this helps.
Can anyone put me on the right path so that i'm able to develop a Pre-loading page which is visible till the application loads in background.
I'd suggest you use an AsyncTask implementation for loading your application in a background thread.
In the AsyncTask's
onPreExecute method you display an
image (splash screen / loading
spinner / progress dialog...),
doInBackground method you load the
necessary data for your application
to start, and in the
onPostExecute method you remove
the preloader image, and display
your application which already has
all the necessary data.
I think you should implement a thread which will show an image related to your application.
After some time you call your first Activity.
I'd like to have a splash screen while loading resources (images and sounds). How do I know everything is loaded?
Are all resources loaded at app startup?
Thanks
For accordingly implementing a splash screen in Android you want to:
Show a foreground screen with some progress indication for the user.
Execute a background thread for doing tasks that take some indefinitive time.
Both threads communicating between them, as you need the foreground to show the progress on the background.
Correctly kill the background thread when it finishes doing it's task. If you are planning to use AsyncTask in Android you have an issue there. (Link)
I've found this tutorial and I strongly suggest it:http://www.41post.com/4588/programming/android-coding-a-loading-screen-part-1
Part 1 accomplish this basic task, part 2 shows you how to correctly kill the AsyncTask. And part 3 puts a customized view in the foreground instead of the ProgressActivity.
You could do all your loading in an asyncTask then your onPostExecute remove the splash screen. This would help ensure that you don't block the UI thread while doing any expensive tasks that could cause an ANR popup.
Here you go, wrote a tutorial on how to create a SplashScreen with a progress bar:
http://blog.blundellapps.com/tut-splashscreen-with-progress-bar/
Basically, instead of your thread it starts an ASyncTask, you pass a reference to your progressSpinner into the ASyncTask and this will update it as the thread is downloading resources (or whatever you want to do).
Here is a complete tutorial on how to get it done. I've used this one myself with great results.
http://www.barebonescoder.com/2010/04/a-simple-android-splash-screen/