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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:56:10+00:00 2026-05-26T09:56:10+00:00

Can you explain me how thread is working. Actually it’s working just fine right

  • 0

Can you explain me how thread is working. Actually it’s working just fine right now but I want to get the logic behind. I think it gives me a chance to do 2 calculation in same time so I don’t have to wait for first calculation to and. But how to use it? Where to put first calculation and where to put second calculation? In C++ I have to get process ID when I’m splitting it and then I have to use an if something like that if(pID==1){//first calculation}

My classes are:
I have a ClassA which is main activity
a ClassB: using as contend view extended to SurfaceView
and a ClassC: using as game loop extended to Thread

and here they are:
ClassA:

public class ClassA extends Activity{ 
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                               WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(new ClassB(this));
    }
}

ClassB:

public class ClassB extends SurfaceView{
//Variables.......................
    private ClassC GameLoop;
//Constructor.....................    
    public GameView(final Context context) {
        super(context);

        GameLoop = new ClassC(this);
        Holder=getHolder();
        Holder.addCallback(new SurfaceHolder.Callback() {
            public void surfaceDestroyed(SurfaceHolder holder) {
                // TODO Auto-generated method stub
            }
            public void surfaceCreated(SurfaceHolder holder) {
                // TODO Auto-generated method stub
            }
            public void surfaceChanged(SurfaceHolder/// blaa bla
                // TODO Auto-generated method stub
            }
        });
        this.setOnTouchListener(new OnTouchListener()
        {    
            //@Override
            public boolean onTouch(View v, MotionEvent event) {
                // TODO Auto-generated method stub
            }
        });
    }
    @Override
    protected void onDraw(Canvas canvas) {
        canvas.drawColor(Color.GREEN);
        //Using canvas and drawing something on it.
    }
}

ClassC:

public class ClassC extends Thread {//GameLoop
    private ClassB view;
    private boolean running = false;

    public ClassC(ClassB view) {
        this.view = view;
    }
    public void setRunning(boolean run) {
          running = true;
    }
    @Override
    public void run() {
        while (running) {
           Canvas c;
           try {
               c = view.getHolder().lockCanvas();
               synchronized (view.getHolder()) {
                   view.onDraw(c);// Here I call onDraw to draw everything
               }
           } finally {
               if (c != null) {
                   view.getHolder().unlockCanvasAndPost(c);
               }
           }
        }
    }
}
  • 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-26T09:56:10+00:00Added an answer on May 26, 2026 at 9:56 am

    Are you asking how threads in general work in android?

    In C++ I assume you were using Threads as a parallel processing tool, to split the load of a repetitive piece of work across a number of processors.

    In Android, unless you are using a multicore device and a specific framework like the Tegra platform, this kind of thread processing is in fact a waste of time. In Android it is better to use threads to perform tasks you don’t want to risk performing on the logic thread or the UI thread.

    In your case I assume you are building a Game using android, I would recommend using two threads: a logic thread, and a UI thread. Have these running asynchronously and your game should run smoothly.

    Sorry I can’t help more, as I’m not sure exactly what your question is.

    More info on Threads in android can be found here Android Developers

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

Sidebar

Related Questions

I'm learning about POSIX threads right now, but I guess this is just a
can some one explain why I face problem with backgroundworker backgroundWorker1_RunWorkerCompleted works just fine
I am working on thread in Iphone. Can anyone explain the difference between [NSThread
Can anyone explain the difference between a fork and a thread?
can anyone please explain the concept of dispatcher, is it one dispatcher per thread
I hope this I can explain what I am trying to achieve: I want
I hope I can explain this right I have two input fields that require
Not sure if I can explain this correctly, but I am trying to execute
I am having a weird problem with C#, I can't yet explain. I actually
Can someone explain to me this StaleDataException 07-11 19:58:23.298 E/AndroidRuntime( 1044): Uncaught handler: thread

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.