我有一个弹出系统,它显示带有 Textview 的弹出警报。Popup 类(如下所示)是通过另一个类的 Intent 调用的。当 Popup 显示在 onCreate 方法上时,Popup 类的代码起作用(完成它的代码显示在 oncreate 类的块注释中)。但是,我的功能是创建弹出窗口,以便它不会停止/暂停后台应用程序。几乎可以获得 Toast 的功能。在不中断后台应用程序的情况下显示弹出窗口。所以我决定使用 AsynchTask 来实现它,但我不断收到运行时异常。有人可以引导我走正确的道路吗?我相信我必须实施 onPostExecute 但不确定我应该如何去做。
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;
}
}
}