Back to project page 2014-Droid-code.
The source code is released under:
GNU General Public License
If you think the Android project 2014-Droid-code listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.androidbook.simpleasync; /*from w ww .j a va 2 s . c o m*/ /* * This class is the an example I coded, it does not use a separate thread * I expect it to cause an ANR * */ import android.app.Activity; import android.os.Bundle; import android.os.SystemClock; import android.widget.TextView; public class SimpleNoBGThread extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.count); TextView tv = (TextView) findViewById(R.id.counter); // Start counting on the main UI thread int i = 0; tv.setText(Integer.toString(i) + "% Complete!"); while (i < 100) { // pause 1000 milliseconds SystemClock.sleep(500); i++; if (i % 5 == 0) // update UI with progress every 5% tv.setText(Integer.toString(i) + "% Complete!"); } tv.setText("Count Complete! Counted to " + Integer.toString(i)); } } // class SimpleNoBGThread