I am looking for some guidance and hopefully someone can tell me the proper way to implement this scenario. In my app I am going to show a splash screen on startup and immediately start downloading some data from internet. When splash screen is finished, after about three seconds, the mapview should be shown. When the downloading of data is finished, after about one to ten seconds, the mapview should be updated with points of interest relating to the downloaded data. How do I best implement this in Android. Of course I first have an activity for the splash screen and another mapactivity for the mapview. But what do I use to download the data and when it is finished notify the mapactivity to update the mapview? Do I use an asynctask?
Best regards
P
SplashScreen does not need to be a separate Activity since it does not handle user events.
Just put splash screen and mapview inside one activity. Use FrameLayout to position splash screen on top of mapview.
Start loading data when Activity starts (onCreate). Use AsyncTask to do network communication in the background while correctly updating view when data arrives.
Create Handler and call postDelayed() to dismiss splash screen after some time.
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 game menu, which is one activity, and an actual game, which is another activity.
I also have a custom Dialog class that displays a "Loading..." text and a spinning wheel. (I could add code, but it's almost identical to a normal ProgressDialog. Nothing special about it).
I wish to start displaying this dialog from the menu activity (when loading), and continue its display for after the transition to the game activity - until the game finishes loading.
Is that even remotely possible? I didn't fid a way to extend a Dialog over 2 activities. It seems to be bound to one.
Is that even remotely possible?
Not as far as I know. A Dialog is a UI element and as such exists withing the 'window' of the Activity which created it. Starting a new Activity obviously means it will cover the previous one and any Dialog it's currently showing.
It seems to me there are only two simple ways of doing what you want...
Make sure that what is 'loading' your game is running in some separate place (Service etc) and progress is accessible from both Activities then simply destroy the first Dialog when the second Activity is started, create a new Dialog and have it pick up from where the first one left off (with progress, messages etc).
If your menu and main game play can be hosted by Fragments then simply swap a menu Fragment to a game Fragment within a single Activity. That way the Dialog will continue to exist without interruption.
I don't think dialog can be extended with two activities, It actually requires a activity context to run. so if activity will be destroyed it will automatically leaked.
Please post answer if you find the way.
I want to show a splash screen between my first and second activity. Both the activities make use of AsyncTask. First being a simple login screen retrieving data for the whole app and second loads the activity specific data. Currently, both the activities have their own ProgressDialogs which is quite naive but they were developed individually and then I wasn’t planning to put them one after the other.
I tried to implement the splash screen only replace a loading process from one activity. But, in order to place a splash screen in between them do I have to transfer all the loading process to a single activity? Which activity should contain the code for the splash screen? I basically want to replace two ProgressDialogs by a single splash screen. What should I do?
I think the simplest way would just make a transitional activity that displays a splash screen, preloads the data for the next activity, then launches the next activity.
Activity A loads Activity B which shows the splash screen while simultaneously running the AsyncTask. Once the AsyncTask completes load Activity C.
I hope I understand your question correctly :-)
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/
I have a splash screen/loading screen that has .setVisibility() to GONE right after the draw call of my large bitmap is completed. The problem is the splash screen takes a bit to popup which i believe is due to the main activity booting up and doing CPU intensive applications on first run. Is there a way to get my splash screen displayed ASAP? Would it be ok if i had it in a different thread maybe? The splash screen is just a bitmap with a progressBar right below it. My layout is xml based so i cant see myself using setContentView. Thanks.
Would it be ok if i had it in a different thread maybe?
In android, when we build an application we may need to display a splash screen ( welcome screen ) for users to intimate some thing & do some other process in background ( like fetching data from DB, Parsing XML , etc.. ), so for that it is preferrable to implement it in a different thread.
I have referred the example on www.androidpeople.com site for the SPLASH SCREEN, you may also Have a look at this example of SPLASH SCREEN .
You want a separate thread to execute tasks in background, while showing progress in the foreground and call the setVisibility(...) method you say after doing so.
I've come across this tutorial: http://www.41post.com/4588/programming/android-coding-a-loading-screen-part-1
I've found it excellent, it's easy to implement, only one class and after part 2 you learn how to really get rid of the AsyncTask definitevely (http://stackoverflow.com/questions/3077461/asynctask-threads-never-die-android).
You can try setting the Splashscreen as a theme to your activity