I have a TextView
on my splash screen and I'm trying to emulate Discord's randomized loading text.
I have the following code, pulled from here:
private void LoadText() {
Runnable runnable = new Runnable() {
@Override
public void run() {
final TextView loadingTextView = findViewById(R.id.loading);
loadingTextView.setText(FetchRandomLoadingText());
}
};
ScheduledExecutorService ex = Executors.newScheduledThreadPool(1);
ex.scheduleAtFixedRate(runnable, 0, 5, TimeUnit.SECONDS);
}
FetchRandomLoadingText()
returns a string from an ArrayList
by index, works fine (tested with Toast
to make sure it wasn't the problem).
This is working fine for one or two updates, but if the splash takes longer (slow internet connection for example) to do its thing, the text stops updating after 2 iterations.
I've looked at the equivalent of setInterval
in JavaScript for Java but the solutions seems to iterate once and then stop all together.
Am I missing something obvious in getting this to endlessly run until I flag for a new Activity to be loaded?