我想在5秒後發送通知。無法在未調用looper的線程內創建處理程序?
我發現此代碼示例在5秒後面做某事,但我只能設置一個Log.e()
。
Notification
方法也有效。但是,如果我要調用的方法setNotification()
,我得到了RuntimeError
後5秒:
不能內螺紋已不叫looper.prepare創建處理程序()。
我發現很多幫助,但沒有任何工作。所以我希望你能幫助我。
public class Reminder {
Timer timer;
public Reminder(int seconds) {
timer = new Timer();
timer.schedule(new RemindTask(), seconds * 1000);
}
}
class RemindTask extends TimerTask {
public void run() {
todo_list rem = new todo_list();
rem.setNotification("Todo!", false, 1);
}
}
public class todo_list extends ListActivity {
public void onCreate(Bundle savedInstanceState) {
new Reminder(5);
}
public void setNotification(String text, boolean ongoing, int id) {}
}