Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6391035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:37:21+00:00 2026-05-25T03:37:21+00:00

In my application i get image from server and those image build animation.this all

  • 0

In my application i get image from server and those image build animation.this all things are gone be right way and i create method for it.this is the method::

  package com.animation;

import java.io.InputStream;
import java.net.URL;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.widget.Button;
import android.widget.ImageView;
public class animation extends Activity {
    Button Buttona;
    AnimationDrawable animation;
    @Override
    public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.main);
        ImageView img = (ImageView) findViewById(R.id.simple_anim);
        animation = new AnimationDrawable();

           try {
               for(int i=0;i<54;i++)
               {    
                xyz("girl000",i);
               }        
           animation.setOneShot(false);
           } catch (Exception e) {
            }
           img.setBackgroundDrawable(animation);
           img.post(new Starter());

    }


    public void xyz(String str,int x)
    {
        try {
            Bitmap bitmap = BitmapFactory.decodeStream((InputStream) new URL(
        "http://201.109.115.111/MRESC/images/test/girl/"+"girl000"+x+".png")
            .getContent());
            Drawable frame =new BitmapDrawable(bitmap);
            animation.addFrame(frame, 50);

        } catch (Exception e) {

        }

    }
    class Starter implements Runnable {

        public void run() {
            animation.start();        
        }


    }
}

now my problem is it is take much time to load image from server so simply i plan to use asyncTask. but problem is i cant get judgment that how can i do this?
can you give me example(Note : i know asyncTask and use already but problem is passing argument as per my xyz() method declare)

Thanks
nik

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T03:37:21+00:00Added an answer on May 25, 2026 at 3:37 am

    Here is the code:

    • Note that the loop now is in the background thread
    • After each loop, you publish the progress to setup the animation frame
    • At the very end, you run onPostExecute to run the remaining code

    Note, that this is just a skeleton and rough sketches, you need to understand and debug it if there is any problem. I haven’t run the code yet

    
        public class Animation extends Activity {
            Button Buttona;
            AnimationDrawable animation;
    
            @Override
            public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
    
                setContentView(R.layout.main);
                animation = new AnimationDrawable();
    
                AsyncTask asyncTask = 
                    new AsyncTask() {
    
                    @Override
                    protected Void doInBackground(Void... params) {
                        try {
                            // Execute this whole loop in background, so it doesn't 
                            // block your UI Thread
                            for(int i=0;i<54;i++) {    
                                xyz("girl000",i);
                            }        
    
                        } catch (Exception e) {
                            return null;
                        }
                    }
    
                    public void xyz(String str,int x) {
                        try {
                            Bitmap bitmap = BitmapFactory.decodeStream((InputStream) new URL(
                                    "http://201.109.115.111/MRESC/images/test/girl/"+"girl000"+x+".png")
                            .getContent());
    
                            // publish progress so that the bitmap is set on the UI Thread
                            publishProgress(bitmap);
                        } catch (Exception e) {
                            // handle error
                        }
                    }
    
                    @Override
                    protected void onProgressUpdate(Bitmap... result) {
                        // handle the progress update to add the animation frame
                        Bitmap bitmap = result[0];
                        Drawable frame =new BitmapDrawable(bitmap);
                        animation.addFrame(frame, 50);
                    }
    
                    @Override
                    protected void onPostExecute(Void result) {
                        if(result != null) {
                            // execute the rest of your instruction after the loop is over here
                            animation.setOneShot(false);
                            ImageView img = (ImageView) findViewById(R.id.simple_anim);
                            img.setBackgroundDrawable(animation);
                            img.post(new Starter());
                        } else {
                            // handle error
                        }
                    }
                };
    
                asyncTask.execute();
            }
    
            class Starter implements Runnable {
                public void run() {
                    animation.start();        
                }
            }
        }
    
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my first iPhone application. So I have this long list of doubts
I am trying to retrieve the image from resource file and tryin to bind
I saved an image using Coredata in my application. Then i imported the Sqlite
I'm creating a small voting application. I need to get the images and their
I'm seeing a behaviour in Firefox which seems to me unexpected. This is not
I wish someone can help me with this one. I have a Spring MVC
I have an activity which shows 3 random images from JSON data off the
I setup sorl-thumbnail according to instructions, but none of the images are appearing when
The Imagepair object is a member variable of some other class.. I want its
Long time lurker, first time poster here. My question is: Using C# 2.0, is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.