Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android loading animation

Tags:

java

android

I am searching for some info on how to create loading animation in android. Is it possible to create this animation that i could call this animation in one thread and end in other ?

I seeking for this:

enter image description here

like image 359
Streetboy Avatar asked Apr 20 '12 08:04

Streetboy


People also ask

Which of the following codes will you use to perform animation in Android?

Animation animation = AnimationUtils. loadAnimation(getApplicationContext(), R. anim. myanimation);


3 Answers

Try below Code

ProgressDialog for showing:

 ProgressDialog mDialog = new ProgressDialog(getApplicationContext());
                mDialog.setMessage("Loading...");
                mDialog.setCancelable(false);
                mDialog.show();

After cancel ProgressDialog below code:

 mdialog.dismiss();
like image 124
Dinesh Avatar answered Oct 07 '22 01:10

Dinesh


This is basically done with an AsyncTask and a ProgressDialog (Using spinner style) that is started and dismissed by the AsyncTask.

like image 36
WarrenFaith Avatar answered Oct 07 '22 02:10

WarrenFaith


You can not start/end ProgressDialog from any thread other that UI thread. In it's simplest for you would want to use AsyncTask methods onPreExecute onPostExecute. But I would be careful with that.

  1. you don't want to lose a reference to dialog from async task (user changes orientation or rotates the screen). So you want to keep WeakReference to dialog
  2. If you're doing serious loading worj, I'd recomment using Service for it and listening for service callbacks (like broadcasts) to control dialog. This will also allow you separate Activity lifecycle from background work.
like image 27
EvilDuck Avatar answered Oct 07 '22 02:10

EvilDuck