Avoid black screen between activities without using AsyncTask - android

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

Related

Splash screen during async

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 :(

Login orientation change

I have problem with android login dialog. I don't want to set android:configChanges="keyboardHidden|orientation" parameter in Manifest because it isn't good android programming practice. On the other hand on orientation change without it applicaction crushes. Is there any good solution in this situation or alternative?
This is an old thread, but I did have similar problems and also did not want to set android:configChanges. I basically nailed the issue down to onSaveInstance(Bundle outstate). Apparently calling Session.saveSession() was dying because my bundle was not "serializable" for whatever reason...

Android screen rotation causes exception

I have a lot ot async tasks in my activity. If screen rotation occurs - they gone. What to do to prevent asynctasks from trowing exception?
I think exception is due to the re starting of the activity in orientation changes, if use android:configChanges="orientation|keyboardHidden" for your activity in your manifest, which prevents restart
use
android:configChanges="keyboardHidden|orientation"
as a attribute of your Activity in AndroidManifest.xml file to prevent reload Activity on screen rotation .
The most proper way to this is to use a fragment to retain the instance of the async task, over rotations.
Here is a link to very simple example making it easy to follow and integrate this technique into your apps. This works brilliantly all buttons and images etc are redrawn as expected
https://gist.github.com/daichan4649/2480065

Suspend orientation change

Documentation says: "a configuration change (such as a change in screen orientation, language, input devices, etc) will cause your current activity to be destroyed, going through the normal activity lifecycle process of onPause(), onStop(), and onDestroy()."
I would like to suspend the orientation change, since it crashes my app if it was done in the middle of a a loop (of reading a file).
How can I do this? Also - looking for some kind of "onOrientationChnage" function :)
First, why not solve the initial problem instead?
90% of the times, the problem that you are facing (when changing orientation) is solved in this question:
Background task, progress dialog, orientation change - is there any 100% working solution?
Read it, correct your code and see if the problems are gone!
If you still want to do it anyway:
Quoting the documentation:
Note: Handling the configuration
change yourself can make it much more
difficult to use alternative
resources, because the system does not
automatically apply them for you. This
technique should be considered a last
resort and is not recommended for most
applications.
Still want to do it? Read the following link (where I also found the quotation):
http://developer.android.com/guide/topics/resources/runtime-changes.html#HandlingTheChange
If you rely on android system to use different layouts when you are on portrait/landscape mode, you'll need to start to handle these differences by yourself. If you don't use these features, you may get away without doing nothing fancy :)
If you always want a particular orientation, you can add android:screenOrientation="portrait" (or ="landscape" as an attribute to your tag in the manifest.
At run time, you can call setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

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