Skip to content

Instantly share code, notes, and snippets.

@michiakig
Created November 19, 2012 20:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michiakig/4113683 to your computer and use it in GitHub Desktop.
Save michiakig/4113683 to your computer and use it in GitHub Desktop.
CheckThread blog post HackerNewsActivityV2Buggy.java
new Thread() {
@ThreadConfined("other")
public void run()
{
try
{
// doing IO off the UI thread -- ok
String feed = IO.getHttp(kHackerNewsRssUrl);
List<String> titles = HackerNewsRSSParser.parseTitles(feed);
for (String t : titles)
{
// updating the UI from off the UI thread -- this MAY blow up, so you shouldn't do it
TextView textView = new TextView(HackerNewsActivityV2Buggy.this);
textView.setText(t);
linearLayout.addView(textView);
}
}
catch (IOException e)
{
e.printStackTrace();
}
}
}.start();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment