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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:01:26+00:00 2026-05-31T14:01:26+00:00

My app has a screen that refreshes every second in AsyncTask: class BarRefresh extends

  • 0

My app has a screen that refreshes every second in AsyncTask:

class BarRefresh extends AsyncTask<Void, Void, Void>{
    @Override
    protected Void doInBackground(Void... params) {
       // doSomething();
        while(redraw){
            for(int i = 0; i < c.sets.size(); i++)
            {
                vals[i] = c.sets.get(i).getLast();
            }
            graph.updateVals(vals);
            graph.postInvalidate();
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            if(isCancelled()){
                break;
            }
        }
        return null;
    }
}

A click on one of the objects opens a new activity with a parameter:

@Override
        public boolean onTouch(View v, MotionEvent ev) {
            // TODO Auto-generated method stub
            float[] coords = new float[2];
            coords[0] = ev.getX();
            coords[1] = ev.getY();
            int set = 0;
            for(int i = 0; i < graph.values.length; i++){
                if(graph.rects[i].contains(coords[0], coords[1]))
                {
                    redraw = false;
                    Bundle chosen = new Bundle();
                    chosen.putInt("set", i);
                    Intent bb = new Intent(GraphTestActivity.this, LineGraphActivity.class);
                    bb.putExtras(chosen);
                    startActivity(bb);
                //  set = i;
                }
            }
            //Toast t = Toast.makeText(GraphTestActivity.this, "KLIKNIETO " + set, Toast.LENGTH_SHORT);
            //t.show();
            return false;
        }

In the new activity constructor looks like that:

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    Bundle pick = getIntent().getExtras();
    setNr = pick.getInt("set");
    c = Common.getInstance();
    set = c.sets.get(setNr);
    graph = new LineGraph(LineGraphActivity.this, set);
    setContentView(graph);
}

Here is where things get weird. On the emulator everything works fine (app is on 2.1 API, so is the emulator), but when I load it up on my phone, five or more instances of the second activity open at the same time and I have to press back button multiple times to go back to the original screen.

My phone is Samsung i5700 Spica with And 2.3.7 (Cyanogen 7.2 NIGHTLY alpha)

  • 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-31T14:01:28+00:00Added an answer on May 31, 2026 at 2:01 pm

    You are probably getting multiple onTouch() events. Verify this through the debugger. on the emulator it’s quite boolean, but on a real touch screen in the micro seconds as your finger is coming in contact with the screen you can receive multiple touch events.

    If you can use a higher-level function like onClick instead of onTouch, do that. If you can’t you need to keep track of the touch down and touch up events and only react to down if it wasn’t already down.

    A hack would be to define your activity as single instance, then you won’t get multiple instances. This is almost certainly not the right thing to do though.

    As a side note, putting Thread.sleep() in your code almost always indicates a lurking bug, and that the code is written incorrectly. If you need something to happen at a later point in your code, use Handler.postDelayed() or a Timer.

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

Sidebar

Related Questions

My app has a main screen that the user always starts at, and from
My app has a welcome screen that can only be shown in portrait mode.
So, I'm building an iOS4 app that has a login screen and has to
G'day All My app has a first run component that presents a login/signup screen
I am building an app that has a login screen that leads to a
I am trying to build an app that has a landing screen with a
My Android app Transdroid offers several home screen widgets. Every AppWidget has 2 'buttons'
The Clock app has a button that dims the screen. I'd like to check
I have a fullscreen iphone web app that has a startup screen that works.
My app has a splash screen activity and that starts an intent for the

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.