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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:14:05+00:00 2026-05-27T12:14:05+00:00

this is my activity code public class HomeActivity extends Activity { private String html

  • 0

this is my activity code

public class HomeActivity extends Activity {

    private String html = "";
    private Handler mHandler;
    private ActionBar actionBar;

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

        actionBar = (ActionBar) findViewById(R.id.actionbar);
        actionBar.setHomeAction(new IntentAction(this, createIntent(this), R.drawable.ic_title_home_default));
        actionBar.setTitle("someTitle");



        Intent intent = new Intent(this, ComposeActivity.class);

        final Action otherAction = new IntentAction(this, intent, R.drawable.ic_title_share_default);
        actionBar.addAction(otherAction);

        mHandler = new Handler();  
    }

    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        if(hasFocus)
            checkPrice.start();
    }

    public static Intent createIntent(Context context) {
        Intent i = new Intent(context, HomeActivity.class);
        i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        return i;
    }


    private Thread checkPrice = new Thread() {
        public void run() {
            actionBar.setProgressBarVisibility(View.VISIBLE);
            try {       
               //...some code
                mHandler.post(showUpdate);
            } catch (Exception e) {
            }
        }
    };  

    private Runnable showUpdate = new Runnable(){
        public void run(){
            actionBar.setProgressBarVisibility(View.GONE);
            Toast.makeText(HomeActivity.this, "HTML Code: " + html, Toast.LENGTH_SHORT).show();
        }
    };

}

After adding the onWindowFocusChanged method the Intent intent
cannot be started anymore. I get following error:

 12-12 10:50:02.468: W/dalvikvm(540): threadid=3: thread exiting with
 uncaught exception (group=0x4001b188) 12-12 10:50:02.468:
 E/AndroidRuntime(540): Uncaught handler: thread main exiting due to
 uncaught exception 12-12 10:50:02.468: E/AndroidRuntime(540):
 java.lang.IllegalThreadStateException: Thread already started. 12-12
 10:50:02.468: E/AndroidRuntime(540):   at
 java.lang.Thread.start(Thread.java:1322) 12-12 10:50:02.468:
 E/AndroidRuntime(540):     at
 HomeActivity.onWindowFocusChanged(HomeActivity.java:58)
 12-12 10:50:02.468: E/AndroidRuntime(540):     at
 com.android.internal.policy.impl.PhoneWindow$DecorView.onWindowFocusChanged(PhoneWindow.java:1969)
 12-12 10:50:02.468: E/AndroidRuntime(540):     at
 android.view.View.dispatchWindowFocusChanged(View.java:3731) 12-12
 10:50:02.468: E/AndroidRuntime(540):   at
 android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:657)
12-12 10:50:02.468: E/AndroidRuntime(540):  at
 android.view.ViewRoot.handleMessage(ViewRoot.java:1819) 12-12
 10:50:02.468: E/AndroidRuntime(540):   at
 android.os.Handler.dispatchMessage(Handler.java:99) 12-12
 10:50:02.468: E/AndroidRuntime(540):   at
 android.os.Looper.loop(Looper.java:123) 12-12 10:50:02.468:
 E/AndroidRuntime(540):     at
 android.app.ActivityThread.main(ActivityThread.java:4363) 12-12
 10:50:02.468: E/AndroidRuntime(540):   at
 java.lang.reflect.Method.invokeNative(Native Method) 12-12
 10:50:02.468: E/AndroidRuntime(540):   at
 java.lang.reflect.Method.invoke(Method.java:521) 12-12 10:50:02.468:
 E/AndroidRuntime(540):     at
 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
 12-12 10:50:02.468: E/AndroidRuntime(540):     at
 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) 12-12
 10:50:02.468: E/AndroidRuntime(540):   at
 dalvik.system.NativeStart.main(Native Method)

Any ideas how to fix this?

  • 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-27T12:14:06+00:00Added an answer on May 27, 2026 at 12:14 pm

    Your onWindowFocusChanged calls Thread.start() several times for the same thread which is incorrect. You may want to use a variable like isStarted to guarantee that Thread.start() is called only once. Or start a new thread each time. That depends on your program’s logic.

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

Sidebar

Related Questions

I have this code: public class Home extends Activity{ @Override public void onCreate(Bundle savedInstanceState)
This is my code: public class MainActivity extends Activity { private ComponentName mService; private
I have this code: public class VoiceActivity extends Activity implements OnClickListener { private TextView
I am using this simple code public class Main extends Activity { private ProgressDialog
I have this code: public class Chronom extends Activity { Chronometer mChronometer; ProgressBar progre;
Here's the code: public class MenuTabActivity extends TabActivity implements OnTabChangeListener{ @Override protected void onCreate(Bundle
My code is : public class EventDataSQLHelper extends SQLiteOpenHelper { private static final String
this is my first activity code: public class hello extends Activity { /** Called
This is my code: public class Alarm extends Activity { /** Called when the
I have following code: public class readSensorsData extends Activity implements SensorListener { /** Called

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.