Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android

Delay for text display

I am trying to make it look like the text in the Interactive story app is typing. Right now I have the text being set to each individual character in the string using a for loop. However, when I use a delay timer, it stalls the app and it never loads the story activity(I checked this using the log, it doesn't show the story activity loading). I was wondering if there is some native android thing or a way to create a delay for my app.

1 Answer

I'm not sure how long your delay is for this; however, it is good to note that the default thread on Android is the UI thread. In general if you have long tasks to complete, it is better to do them on separate threads so that your user interface remains responsive. You might consider putting the delay code for this typing behavior on a separate thread by using an asynctask for example, http://www.compiletimeerror.com/2013/01/why-and-how-to-use-asynctask.html#.VO4YaLPF8h4

You might also double check that your delay time is reasonable. Good luck!

Thanks, I'll try this in my program.