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 5962851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:09:50+00:00 2026-05-22T19:09:50+00:00

I have to change background image at every 30 seconds but i am not

  • 0

I have to change background image at every 30 seconds but i am not getting proper result

I have tried with thread and TimerTask. but no work.
I have port1, port2…etc images.

In TimerTask background is gone.

class Task1 extends TimerTask {
    public void run() {
        System.out.println("Checking a");
        Random r = new Random();
        int i = r.nextInt(3) + 1;
        rl.setBackgroundResource(getResources().getIdentifier(
                    "port" + i, "drawable","com.samcom.breakingdowncd"));

    }
}

Timer timerBackground = new Timer();
timerBackground.scheduleAtFixedRate(new Task1(), 0, 30000);

Its not working, any help will be appreciated.
Thanks

  • 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-22T19:09:51+00:00Added an answer on May 22, 2026 at 7:09 pm

    use this, it works

        private static final long GET_DATA_INTERVAL = 1000;
        int images[] = {R.drawable.cloud1,R.drawable.cloud2};
        int index = 0;
        ImageView img;
        Handler hand = new Handler();
    
        public void onCreate(Bundle savedInstanceState)
        {
            super.onCreate(savedInstanceState);
            this.setContentView(R.layout.main);
            img = (ImageView) findViewById(R.id.image);
            hand.postDelayed(run, GET_DATA_INTERVAL);
        }
    
        Runnable run = new Runnable() {
            @Override
            public void run() {
                img.setBackgroundDrawable(getResources().getDrawable(images[index++]));
                if (index == images.length)
                    index = 0;
                hand.postDelayed(run, GET_DATA_INTERVAL);
            }
        };
    

    XML Code:

    <?xml version="1.0" encoding="UTF-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/line">
        <ImageView 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/image"
        />
    </LinearLayout>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How to change cell background image on click on cell in iphone????I have tried
I have a website and I want an image to change every 5 seconds,
So This website: http://www.atomicdust.com/ They have a background image on every page but when
so I have a simple problem. I have a hover background image change effect,
i have many div's with the same background image and i want change this
i want to have a background thread in my app that changes an image
I want to change the background image of every element on a page by
I'm trying to set a background-image in a div to change every second or
I want to change my background image of my html on every refresh. This
I need change background of all text that have two spaces from the start

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.