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

  • Home
  • SEARCH
  • 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 7808311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:06:05+00:00 2026-06-02T03:06:05+00:00

I have a layout with 2 buttons that each activates animation. On button click

  • 0

I have a layout with 2 buttons that each activates animation. On button click the layout with buttons disappearing and the animation starts. It works except one problem, I can`t activate the second animation after the first because memory problem. After one of the animations is played i have to somehow free memory so the second animation could load. How can I free the animation and delete all frames?

Here is my code:

public class BermadMain extends Activity {
public static final String TAG = "Bermad";

AnimationDrawable animation, animation2, animation3;
ImageView imageAnim;
RelativeLayout lay;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

   lay = (RelativeLayout) findViewById(R.id.rallay);


  imageAnim =  (ImageView) findViewById(R.id.imageView1);

    final Button refinery = (Button) findViewById(R.id.refinery);
    refinery.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            int i=85;
            animation = new AnimationDrawable();
            animation.addFrame(getResources().getDrawable(R.drawable.ref1), i);
            animation.addFrame(getResources().getDrawable(R.drawable.ref2), i);
            animation.addFrame(getResources().getDrawable(R.drawable.ref3), i);
            animation.addFrame(getResources().getDrawable(R.drawable.ref4), i);
            animation.addFrame(getResources().getDrawable(R.drawable.ref5), i);
            animation.addFrame(getResources().getDrawable(R.drawable.ref6), i);
            animation.addFrame(getResources().getDrawable(R.drawable.ref7), i);
            animation.addFrame(getResources().getDrawable(R.drawable.ref8), i);
            animation.addFrame(getResources().getDrawable(R.drawable.ref9), i);
            animation.addFrame(getResources().getDrawable(R.drawable.ref10), i);
            animation.addFrame(getResources().getDrawable(R.drawable.ref11), i); 
            animation.addFrame(getResources().getDrawable(R.drawable.ref12), i); 
            animation.addFrame(getResources().getDrawable(R.drawable.ref13), i);

            imageAnim.setBackgroundDrawable(animation);
            imageAnim.post(new Refiney());
            lay.setVisibility(View.GONE);


        }
    });

    final Button oil = (Button) findViewById(R.id.oil);
    oil.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            int i=85;
            animation2 = new AnimationDrawable();
            animation2.addFrame(getResources().getDrawable(R.drawable.oil1), i);
            animation2.addFrame(getResources().getDrawable(R.drawable.oil2), i);
            animation2.addFrame(getResources().getDrawable(R.drawable.oil3), i);
            animation2.addFrame(getResources().getDrawable(R.drawable.oil4), i);
            animation2.addFrame(getResources().getDrawable(R.drawable.oil5), i);
            animation2.addFrame(getResources().getDrawable(R.drawable.oil6), i);
            animation2.addFrame(getResources().getDrawable(R.drawable.oil7), i);
            animation2.addFrame(getResources().getDrawable(R.drawable.oil8), i);
            animation2.addFrame(getResources().getDrawable(R.drawable.oil9), i);
            animation2.addFrame(getResources().getDrawable(R.drawable.oil10), i);
            animation2.addFrame(getResources().getDrawable(R.drawable.oil11), i); 
            animation2.addFrame(getResources().getDrawable(R.drawable.oil12), i); 
            animation2.addFrame(getResources().getDrawable(R.drawable.oil13), i); 

            imageAnim.setBackgroundDrawable(animation2);
            imageAnim.post(new Oil());
            lay.setVisibility(View.GONE);

        }
    });


}

public void onBackPressed() {

    lay.setVisibility(View.VISIBLE);
    return;
}   

class Refiney implements Runnable {

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

class Oil implements Runnable {

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


} 
  • 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-06-02T03:06:06+00:00Added an answer on June 2, 2026 at 3:06 am

    try to add largeHeap=true in your application tag of your manifest to know if it’s only a memory problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What i have: I have a calculator layout, with many buttons. And each button
I have a linear layout with several buttons in it. The button images are
I have a listView, where each row has a button in the row layout.
I have this layout that works correctly, a relative layout with a text view
In my soundboard app I have 80 buttons that have a on click listener
My Application have 5 activities(A1,A2,A3,A4,A5). Each activity have one text view and one button(B1,B2,B3,B4,B5).
I assumed that each layout's element id's such as buttons, textviews, edittexts, etc. were
I have a widget that contains 4 buttons to show 4 stock prices, each
I have a button that basically looks like this: <Button android:id=@+id/admin_new_questions android:layout_width=fill_parent android:layout_height=wrap_content android:text=See
How to align the buttons bottom of the screen.In the layout i have header

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.