Runtime exception from AsynchTask
I have a Popup system that displays Popup alerts with a Textview. The
Popup class (shown below) is called through an Intent from another class.
The code for the Popup class works when the Popup is displayed on the
onCreate method (the code that makes it is done is shown in block comments
in the oncreate class). However, my function is to create the popups so
that it does not stop/pause the background applications. Pretty much get
the functionality of a Toast. Display the Popup without interrupting the
background apps. So I have decided to implement this using AsynchTask but
I keep getting a the run time exception. Could someone guide me in the
right path? I believe I must implement a onPostExecute but not sure how I
should go about this.
public class Popups extends Activity {
private Dialog mDialog;
//static final String ACTION = "android.provider.Telephony.SMS_RECEIVED";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.popups);
//IntentFilter filter = new IntentFilter(ACTION);
//this.registerReceiver(mReceivedSMSReceiver, filter);
/*
String message = getIntent().getStringExtra("message");
TextView messageView = (TextView) findViewById(R.id.message);
messageView.setText(message);
Handler handler = new Handler();
long delay = 5000;
handler.postDelayed(new Runnable() {
@Override
public void run() {
Popups.this.finish();
}
}, delay);
*/
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) {
Handler handler = new Handler();
long delay = 5000;
handler.postDelayed(new Runnable() {
@Override
public void run() {
Popups.this.finish();
}
}, delay);
messageView.setText(message);
return 1;
}
}
}
No comments:
Post a Comment