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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:04:22+00:00 2026-05-17T00:04:22+00:00

I’m using code similar to whats below with the exception that the thread is

  • 0

I’m using code similar to whats below with the exception that the thread is started via a button press. When I press the button, the data at the url is grabbed and it switches me over to the other activity. The issue i’m having is when I’m at the other activity and hit the backbutton I get an Exception saying that the thread has already been started. I’ve tried killing the thread when the activity loads checking for isAlive but it won’t seem to die. Does anyone happen to know how I would get this activity back to it’s original state with the created thread not running?

import java.io.BufferedInputStream;  
import java.io.InputStream;  
import java.net.URL;  
import java.net.URLConnection;  
import org.apache.http.util.ByteArrayBuffer;  

public class Iconic extends Activity {  
private String html = "";  
private Handler mHandler;  

public void onCreate(Bundle savedInstanceState) {  
    super.onCreate(savedInstanceState);  
    setContentView(R.layout.main);  
    mHandler = new Handler();  
    checkUpdate.start();  
}  

private Thread checkUpdate = new Thread() {  
    public void run() {  
        try {  
            URL updateURL = new URL("http://iconic.4feets.com/update");  
            URLConnection conn = updateURL.openConnection();  
            InputStream is = conn.getInputStream();  
            BufferedInputStream bis = new BufferedInputStream(is);  
            ByteArrayBuffer baf = new ByteArrayBuffer(50);  

            int current = 0;  
            while((current = bis.read()) != -1){  
                baf.append((byte)current);  
            }  

            /* Convert the Bytes read to a String. */  
            html = new String(baf.toByteArray());  
            mHandler.post(showUpdate);  
        } catch (Exception e) {  
        }  
    }  
};  

private Runnable showUpdate = new Runnable(){  
    public void run(){  
        Intent newIntent = New Intent(Iconic.this, otherClass.class);
        startActivity(newIntent);
    }  
};  

}

  • 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-17T00:04:23+00:00Added an answer on May 17, 2026 at 12:04 am

    I had a similar problem with one of my applications: I was doing something on a different thread, and while the thread was running the user would switch to landscape mode creating a new activity. Once the thread finished the application would force close because the thread was pointing to an activity that no longer existed.

    My solution to this problem was to use AsyncTask. Basically it abstracts a thread and a handler, and allows you to get periodical progress updates on your background task (ie. implement something like a ProgressBar). I also called AsyncTask.cancel() from my Activity.onDestroy() method so when the activity was destroyed, the AsyncTask would stop running.

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
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 am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am doing a simple coin flipping experiment for class that involves flipping a
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.