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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:08:05+00:00 2026-05-28T00:08:05+00:00

Hullo, I have an activity whose layout is made of a single FrameLayout. I

  • 0

Hullo,

I have an activity whose layout is made of a single FrameLayout. I have a class that extends View which is then added onto this layout.

I want to continually draw to this view, like in a game loop.

Problem is I’m new to android and this Threading stuff is making no sense..

Can I really not update the layout unless I’m in the main UI thread?
How do I go about initialising Threads? 🙁

EDIT::This is what I’ve come up with, but it doesn’t update my frame with anything.

    public class GameFrame extends View
    {
        private GameThread m_gt;

        public GameFrame(Context context, int width int height){
                //do some initialisation stuff
        }

        public GameThread getGameThread(){
                if(m_gt != null){
                    return m_gt;
                }else{
                    m_gt = new GameThread(this);
                    return m_gt;
                }
        }
        @Override
        public void onDraw(Canvas canvas){
                //Draw loads of stuff
        }

        public class GameThread extends AsyncTask<Void, Void, Void>
        {

            private GameFrame m_gf;

            public GameThread(GameFrame gf){
                m_gf = gf;
            }

            @Override
            protected void onProgressUpdate(Void... arg0){
                System.out.println("Wahoo");
                m_gf.invalidate();
            }

            @Override
            protected Void doInBackground(Void... arg0) {
                long start, end;
                while(some bool){

                    System.out.println("Threadin'");

                    publishProgress();

                    //Fiddle with some values
                }
                return null;
            }

        }
    }

And then to initialise it in main activity:

private FrameLayout frame;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {

    ...

    frame = (FrameLayout) findViewById(R.id.gameframe);
    GameFrame gf = new GameFrame(this, width, height);

    frame.addView(gf);
    gf.getGameThread().execute();
}

Is my understanding of Async correct? Should this work given valid code in onDraw?

I should probably say the print outs “wahoo” and “threading” are being printed out numerous times so something must be happening right. More crucially if it has printed “wahoo” then surely it should next redraw my View…but nothing happens 🙁

  • 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-28T00:08:06+00:00Added an answer on May 28, 2026 at 12:08 am

    You use an AsyncTask

    This has two method that allow you to update the main UI before and after the thread has ran

    Also as Tom said in the comment, if you want to continue to update the main UI while the asynctask is being ran, check out this You can do this via publishProgress()

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

Sidebar

Related Questions

I have an Activity which I start like this: public class MyProblemsActivity extends ListActivity
Right now I have an alarm on my main activity which launches a class
Hello I have a datatable that I would like to filter with a single
I have one Activity in which I try to show some simple messages, and
Hello i have a simple expandable list activity that was working fine until i
I have an activity that pulls a String Array from xml and displays a
Hello I have an Activity that shows a CountDown in a textView (using CountDownTimer),
I have this activity, package org.dewsworld.ui; import android.app.Activity; import android.os.Bundle; import android.widget.TextView; public class
Hello I have like this 2 tables class User public int UserId{get;set;} { ....
hello I have my code that connects to my ftp server $conn_id = ftp_connect($ftp_server);

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.