Android与IntentService的轮换
我有一个应用程序,它使用IntentService运行后台任务,从网站中提取数据,解析数据,并根据结果创建日历事件。一切似乎都正常,除了我遇到了一个轮换问题。 使用下面的代码,当我旋转屏幕时,ProgressDialog(进程对话框)保持可见,但在流程更新时不会用新文本更新,并且在调用完成后也不会消失。我使用的是IntentService而不是ASyncTask,因为用户还可以安排IntentService在其他时间运行,而无需与应用程序交互。感谢您的帮助,谢谢Android与IntentService的轮换,android,rotation,intentservice,Android,Rotation,Intentservice,我有一个应用程序,它使用IntentService运行后台任务,从网站中提取数据,解析数据,并根据结果创建日历事件。一切似乎都正常,除了我遇到了一个轮换问题。 使用下面的代码,当我旋转屏幕时,ProgressDialog(进程对话框)保持可见,但在流程更新时不会用新文本更新,并且在调用完成后也不会消失。我使用的是IntentService而不是ASyncTask,因为用户还可以安排IntentService在其他时间运行,而无需与应用程序交互。感谢您的帮助,谢谢 public void onCr
public void onCreate(Bundle savedInstanceState) {
Object retained = getLastNonConfigurationInstance();
if (retained instanceof CalendarHandler) {
// CH is a class level variable defined at the top which references my IntentService, aptly named CalendarHandler
ch = (CalendarHandler) retained;
ch.setActivity(this);
} else {
ch = null;
}
activity = this;
btnLogin.setOnClickListener(OnClickListener(View view) {
ch = new CalendarHandler();
ch.setActivity(MyTlc.this);
// Do other stuff, like run the intent service
}
}
public Handler handler = new Handler() {
public void handleMessage(Message message) {
// We read the information from the message and do something with it
// based on what the result code is
String result = message.getData().getString("status");
if (result.equals("ERROR")) {
activity.removeDialog(PROGRESS_DIALOG);
results.setText(message.getData().getString("error"));
} else if (result.equals("DONE")) {
activity.removeDialog(PROGRESS_DIALOG);
int count = message.getData().getInt("count", 0);
activity.results.setText("Added " + count + " shifts to the calendar");
} else {
activity.pDialog.setMessage(result);
}
super.handleMessage(message);
}
};
据我所知,这应该是可行的,就像我说的ProgressDialog确实保持正常,我只是在旋转后无法将信息传递给对话框