Skip to content

Instantly share code, notes, and snippets.

@mumayank
Created February 17, 2017 07:05
Show Gist options
  • Save mumayank/b4e167f215832b7fcc24c167afa5e6e7 to your computer and use it in GitHub Desktop.
Save mumayank/b4e167f215832b7fcc24c167afa5e6e7 to your computer and use it in GitHub Desktop.
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
new CountClass().execute("name 1", "name 2", "name 3");
}
class CountClass extends AsyncTask<String, String, String> {
protected String doInBackground(String... strings) {
for (int i=0; i<strings.length; i++) {
try {
Thread.sleep(1000);
publishProgress(strings[i]);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
return "done";
}
protected void onProgressUpdate(String... progress) {
((TextView) findViewById(R.id.progressTextView)).setText(progress[0]);
}
protected void onPostExecute(String result) {
((TextView) findViewById(R.id.progressTextView)).setText(result);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment