Splash screen during async - android

I have an android app which does a lot of background processing on launch so for this I've set a content view with an indeterminate progress bar and then during async onprogressupdate I've set the text of the action being carried out. I would like to instead display my own splash screen with again a textview underneath where I can display the current action. I've researched into using surfaceviews and a thread - I'm not sure however if this is the best way to do this. I plan on displaying a sequence of pngs similar to a boot animation which loops until the async finishes.
So my question is: is a surface view class that implements the runnable the best way to accomplish this or is there a better way?
Thank you in advance!

I'm note quite sure about my answer but I guess surfaceview is a more reliable option for this task. If you use several PNGs instead then you need to cache them for memory purposes and this might cause a little problem for your invalidate method in your animation loop.

You could use a transparent activity as your splash screen which would allow you to do pretty much anything you want whilst it was displayed.

Went for AnimationDrawable in the end which was easy to use and worked amazingly. Credit to vmironov for the idea, unfortunately I can't accept a comment as an answer :(

Related

Newbie in Android development. Implement several different processes in an activity

I'm begining to learn android development, and I'm trying to make an app just to learn the language and philosophy.
This app, has to show an image in the middle of the screen, a button below, and a chronometer in the right side. When the app starts, the chronometer has to begin a countdown. When the user press the button, a blur effect has to be applied to the image, and the seconds left to finish the countdown increase by 10.
I almost know how to program the blur efect to the image, the button press, and the countdown and increase by 10 whenever the button is pressed. But I'm not sure about putting all together.
As far as I know, it should be done by designing an activity, and putting inside the activity the image, the button, and another image or a set of changing images or text for the countdown clock. But as I advance in my studied, today I have read that in order to manage different actions in an activity it is neccesary to do it by using fragments. And I have found much complex programming fragments than activities.
So the question is: can I make what I'm trying to do by a simple activity and defining classes and methods for the image effect and the countdown clock or have I to make it with fragments?
Thank you very much.
today I have read that in order to manage different actions in an activity it is neccesary to do it by using fragments
To be blunt, either you either misunderstood what you read, or you are reading the wrong material.
can I make what I'm trying to do by a simple activity and defining classes and methods for the image effect and the countdown clock
Yes.
have I to make it with fragments?
No. It is possible that the whole UI might be a fragment, particularly if it might be shown alongside something else in some cases (e.g., a tablet) and not in others (e.g., a phone). And there is nothing stopping you from making that UI using several fragments, though that would be rather unusual.
As others have already conveyed, no need to go with fragments.. Activity wud suffice.. As far as putting it together is considered, I guess you need to learn more about layouts.. Layouts are the files which basically help you put things on UI as you want it to look like.. There are plenty of material available online for understanding layouts.. Happy learning.. :)

Avoid black screen between activities without using AsyncTask

I would like to avoid or customize these black transitions between activities, they are annoying.
I've read that the solution is using AsyncTask but I would like to know if there is another way of doing the same.
Are you using
android:launchMode="singleInstance"
by any chance? My activities were light as a feather, but I was experiencing a 200ms delay using singleInstance. Changing to standard resolved the issue.
1- using the progress bar in onCreate and do bulky operation then handler.postDelayed or in Async task......
2-
I think inserting the animation while activity transaction is also a option using overridePendingTransition......... but have doubt it may increase the waiting time :(
http://blog.blundell-apps.com/animate-an-activity/
http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/Animation.html
http://www.warriorpoint.com/blog/2009/05/26/android-switching-screens-in-an-activity-with-animations-using-viewflipper/
http://chrisrisner.com/31-Days-of-Android--Day-17%E2%80%93Animating-between-Activities

Android - Textview or Drawable generated and animated programmatically

First off, I'm a beginner. If this is way beyond the scope of a beginner's first application, just tell me.
The best way to explain what I want is as an example: In Robo Defense, when you kill something, a little $10 pops up, animate translates/fades up about 5% of the screen and disappears. (almost like a toast, appears on top of canvas)
I'm looking for something similar to that same effect. As a like, top-layer drawable that ignores the underlying defined XML layout. I can handle the animation part of the code, but I'm curious as to how to create and inflate that view without wreaking chaos on my current layout. If it would be easier as a drawable instead of text, thats really not a big problem for my project. It is simply imformative, no interactivity at all, it will just be a quick little 500ms artifact to show that an action has occurred.
I could use a pointer in the right direction, or some similar code examples please.
I think you would create the TextView within your Java code, and then use an animation to make it rise and fade, once the animation has finished, destroy the TextView.
I've never done this before, but I think that should work!
To anyone else who is wondering, I ended up accomplishing this via wrapping my entire layout in RelativeLayout, making the appropriate changes necessary, then creating a TextView programmatically with layout_above, and then calling an Animation on it.

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/

android splash screen/ loading 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

Categories

Resources