Adding Progress bar in Global application in android - android

I would like to load progress bar when loading the application. I have 60 sound files which I have put in global application using sound pool. When I launch the application the application goes blank and it takes 30 to 40 seconds to load.
Instead of blank screen is it possible to put some progress bar with a background image until the application loads all the sound files?
I found out the global application doesn't support progress bar or background image? Is this true?
If not can somebody help me out in the above?
Thanks!

Load your sound files in an AsyncTask or a Thread.
You can set an OnLoadCompleteListener to know exactly when loading finishes.

If I'm right, and you mean your Application class, than you can't show a progressbar from there. But you have to have at least one activity, and you can show progressbars in your activity.
Also, you shouldn't make heavy operations on the UI thread such as this. Load the sounds in an AsyncTask, show the progressbar in the onPreExecute() method and hide it in the onPostExecute() method.

Related

Show preloader before activity loaded [duplicate]

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!

How to do a spinning animation while downloading a file

I have a program that copies a file to the sd card. The program takes a while to run, and now it just freezes while the file is being copied.
I saw some other programs that have a animation of a wheel spinning in the center of the screen while the file is being down loaed.
I tried to google spin control, but this brought up animation about a selector control using spinning wheels.
Is this feature built into the android?
Use a ProgressBar widget with indeterminate="true". You can use a ProgressDialog, read http://developer.android.com/guide/topics/ui/dialogs.html
Also, learn about threads, as you should be doing your file save in a background thread. http://developer.android.com/guide/components/processes-and-threads.html
You should use an AsyncTask to download the file. This will prevent your UI from freezing, and also easily allows you to show progress information if you want. If you want to let it download in the background, and let the user continue using the app, that's doable as well.
You can find an AsyncTask in one of my open source projects that downloads a file and shows the progress information using a progress bar here. You can change the style of the progress dialog to suit your needs.
I'm assuming you're using some sort of AsyncTask to download it?
If this is the case you can make an indeterminate progress bar start spinning right before you call task.execute() and then in onPostExecute() you can set the progress bar's visibility to view.GONE
here is an example on progress bars: http://codehenge.net/blog/2011/06/android-development-tutorial-progressbar-example/

setContentView taking long time (10-15 seconds) to execute

I have a large activity that contains 100 or more buttons. But it's working fine once loaded. Problem however is loading. From clicking its launch icon to getting the first view it takes 10-12 seconds. Until the first view, it shows gray title bar in black background.
At least, I want to show a simple progress bar or dialog while its loading. But it seems like you cannot show anything before setContentView executed. I think I have tried everything I could without any success. If you can give me any hint or idea, I would be thankful.
UPDATE:
I found a dramatic resolution. It takes now a second to load the view. I didn't use splash, thread or async task at all - BTW, don't try to use thread or async on UI because Android UI is not thread-safe. Problem was that those buttons were based on a custom class that requires initialization to load same resource. - so 100 or more file operations were happening on setContentView. Making them a just single loading solved my problem.
You are loading data on same UI thread , so nothing will be desplayed during the time of loading .
Use Async Task for loading in separate thread.
1)Show a progressBar in onPreExecute()
2)load data in doInBackground() . no UI related stuff here
3) Update changes on UI ,hide progressBar in onPostExecute()
Use this code before setContentView() is called. Maybe it helps.
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
requestWindowFeature(Window.FEATURE_PROGRESS);
setProgressBarIndeterminateVisibility(true);
setProgressBarVisibility(true);

Android Progress Dialog

I have a WidgetProvider which is around for milliseconds. It takes in an intent, and it kicks off a service which takes maybe noticeable time. I wanted to display something to the user during this delay like a progress bar that will block user, but the BroadcastReceiver/WidgetProvider seems like the wrong place to start up a progress bar. Where should I issue the Progress Bar in this case? Service maybe? but service might not be part of UI at all?
Where should I issue the Progress Bar in this case?
From a UI perspective, your only choice is to have it in the app widget itself. ProgressBar is one of the valid widgets to have in an app widget layout.
In terms of who updates the RemoteViews of your app widget to display/update/remove the ProgressBar, that is probably your Service in whatever background thread you are using for the "noticeable time".
Have you tried putting a progress bar in the notifications pull down? Doing something like the market displays when you're downloading an app should work really well, and execute in the background well.
Use can use AsynTask to display progress bar.

Splash screen while loading resources in android app

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/

Categories

Resources