AsyncTask and Timer
For my assignment, I am creating a TextView popup that popups on the
screen. Its called by an Intent in another class. I want to make sure that
when the Popup appears the phone functions is not disturbed (in other
words, run in the background, like a Toast)
Here is what I have attempted so far:
public class Popups extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.popups);
PopupAsynch myPopup = new PopupAsynch();
myPopup.execute(1);
}
private class PopupAsynch extends AsyncTask<Integer, Void, Integer>
{
TextView messageView = (TextView) findViewById(R.id.message);
String message = getIntent().getStringExtra("message");
@Override
protected Integer doInBackground(Integer... params) {
private Timer timer;
timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
Popups.this.finish();
messageView.setText(message);
}
});
}
}, 0, 5000);
}
}
When I do this, the Popups don't appear and gives a RunTimeException:
AsyncTask#1 Please correct me with that I am doing wrong
No comments:
Post a Comment