我不确定我完全理解从子活动返回后需要做什么才能检索数据。我不需要将数据传递给父活动。我使用this作为参考,他们确实提到了onPause和onResume以及可能的解决方案,但是我应该使用保存的首选项而不是onSaveInstanceState和onRestoreInstanceState吗?它在检查布尔值的后台任务中失败。我还使用此this作为进一步的帮助。
以下代码:
@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
super.onSaveInstanceState(savedInstanceState);
// Save UI state changes to the savedInstanceState.
// This bundle will be passed to onCreate if the process is
// killed and restarted.
savedInstanceState.putString("type",type);
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
// Restore UI state from the savedInstanceState.
// This bundle has also been passed to onCreate.
super.onRestoreInstanceState(savedInstanceState);
type = savedInstanceState.getString("type");
}
public class getFeed extends AsyncTask<String, Void, Void>{
@Override
protected Void doInBackground(String... strings) {
ParseQuery<ParseObject> contentFeed = new ParseQuery<>("UserCommentary");
if(type.equals("object1")){
//Query for object1
} catch (ParseException e) {
e.printStackTrace();
}
}
else if(type.equals("object2")){
//Query for object2
}
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
mySwipeRefreshLayout.setRefreshing(false);
commentary.setAdapter(vCommentDetailAdapter);
vCommentDetailAdapter.notifyDataSetChanged();
}
编辑:为代码添加了更多信息