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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:08:01+00:00 2026-05-24T13:08:01+00:00

I’m trying to create a new thread in the onCreate() of an activity, but

  • 0

I’m trying to create a new thread in the onCreate() of an activity, but instead of creating a new thread and executing the runnable’s code in it, the runnable code is executing in the main thread of my program. A new thread never seems to be created.

The onCreate() code:

@Override
protected void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.monster_layout);
    runningMonsterViewActivity = this;
    Thread.currentThread().setName("Main Thread");
    Log.v(TAG, "onCreate() has run");
    Thread genThread = new Thread(new TestRunnable());
    genThread.run();
}

The runnable code:

import android.os.Handler;
import android.util.Log;

public class TestRunnable implements Runnable{
String TAG = "TestRunnable";

    public TestRunnable()
    {
    //  mainThreadHandler = h;
    }
    @Override
    public void run() {
        for(int i=0; i < 1000; i++){
            Log.v(TAG, new Integer(i).toString());
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

    }
}

The stack trace I got when I paused the code when it was executing:

DalvikVM[localhost:8621] (Suspended)    
    Thread [<1> Main Thread] (Suspended)    
        VMThread.sleep(long, int) line: not available [native method]   
        Thread.sleep(long, int) line: 1306  
        Thread.sleep(long) line: 1286   
        TestRunnable.run() line: 18 
        Thread.run() line: 1096 
        MonsterViewActivity.onCreate(Bundle) line: 49   
        Instrumentation.callActivityOnCreate(Activity, Bundle) line: 1047   
        ActivityThread.performLaunchActivity(ActivityThread$ActivityRecord, Intent) line: 2627  
        ActivityThread.handleLaunchActivity(ActivityThread$ActivityRecord, Intent) line: 2679   
        ActivityThread.access$2300(ActivityThread, ActivityThread$ActivityRecord, Intent) line: 125 
        ActivityThread$H.handleMessage(Message) line: 2033  
        ActivityThread$H(Handler).dispatchMessage(Message) line: 99 
        Looper.loop() line: 123 
        ActivityThread.main(String[]) line: 4627    
        Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]  
        Method.invoke(Object, Object...) line: 521  
        ZygoteInit$MethodAndArgsCaller.run() line: 868  
        ZygoteInit.main(String[]) line: 626 
        NativeStart.main(String[]) line: not available [native method]  
    Thread [<6> Binder Thread #2] (Suspended)   
    Thread [<5> Binder Thread #1] (Suspended)   
    Daemon System Thread [<3> Signal Catcher] (Suspended)   
    Daemon System Thread [<2> HeapWorker] (Suspended)   
  • 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-24T13:08:02+00:00Added an answer on May 24, 2026 at 1:08 pm

    You just need to change genThread.run(); to genThread.start();

    Right now, your code calls the run() method from the main thread. start() will actually start a new thread and will execute the run() method on that thread, which is the desired behaviour.

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

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into

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.