how to update listview on backpressed in nested fragment?

Multi tool use
how to update listview on backpressed in nested fragment?
This is my Fragment where I have a list view and I am populating it with ChapterListAdapter.
Curriculum Fragment
public class CurriculumFragment extends Fragment implements
ResponseDelegate {
Context contextd;
ListView curriculumList;
FragmentActivity mActivity;
boolean onResult=false;
int requestCode, resultCode;
Intent data;
String courseId;
private RequestedServiceDataModel requestedServiceDataModel;
private ArrayList<ChapterItem> courses = new ArrayList<>();
private ChaptersListAdapter adapter;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
contextd = container.getContext();
View rootView = inflater.inflate(R.layout.fragment_circulam, container, false);
courseId = getArguments().getString("course_id","2");
curriculumList = (ListView) rootView.findViewById(R.id.circulamList);
adapter = new ChaptersListAdapter((AppCompatActivity) getActivity(), courses);
curriculumList.setAdapter(adapter);
serverRequestForCompleteModule(); // This function fill arraylist courses with data.
return rootView;
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
mActivity = (FragmentActivity) activity;
}
@Override
public void onDetach() {
super.onDetach();
contextd = null;
mActivity = null;
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent
data) {
super.onActivityResult(requestCode, resultCode, data);
if(resultCode == getActivity().RESULT_OK && requestCode == 1111)
{
courses.clear();
courses = (ArrayList<ChapterItem>) data.getSerializableExtra("list");
adapter = new ChaptersListAdapter((AppCompatActivity)mActivity,
courses);
curriculumList.setAdapter(adapter);
}
}
OnItemclick of ChapterListAdapter I am opening Activity MediaplayerActivity3 like this
ChapterListAdapter
void dialogMediaPlayer(final ArrayList<ChapterItem.Module> mlist, final int position, String title, String imageUrl,String chapname,boolean audioStream) {
Intent mint = new Intent(contextd, MediaPlayerActivity3.class);
Bundle bundle = new Bundle();
bundle.putSerializable("courselist",list);
bundle.putSerializable("list",mlist);
bundle.putInt("gpos",glPos);
bundle.putInt("pos",position);
bundle.putString("title",title);
bundle.putString("image",imageUrl);
bundle.putString("chapter",chapname);
bundle.putBoolean("stream",audioStream);
mint.putExtras(bundle);
contextd.startActivityForResult(mint,1111);
contextd.overridePendingTransition( R.anim.slide_up, R.anim.slide_down );
}
Now I do My work In Activity and Now when I backpress I want to update listView in Curriculum Fragment, which I am doing through OnActivityResult method but in onActivityResult method getActivity() always return null.
Onbackpressedmethod in Activity is as follows
MediaPlayerActivity3
public class MediaPlayerActivity3 extends AppCompatActivity implements ResponseDelegate {
@Override
public void onBackPressed() {
saveInsatance(tmpModule.get(position).getModule_id());
stop = false;
myHandler.removeCallbacks(UpdateSongTime);
int x1=0;
if(tmpModule.get(posit).getIs_module_comeplete().equals("0")){
x1=(int)(TimeUnit.MILLISECONDS.toSeconds((long)finalTime)-TimeUnit.MILLISECONDS.toSeconds((long)startTime));
if(x1<5){
serverRequestQuizForAudeoComplite(tmpModule.get(posit).getModule_id());
tmpModule.get(posit).setIs_module_comeplete("1");
}
}
courses.get(glpos).setModule_files(tmpModule);
Intent returnIntent = new Intent();
Bundle bundle = new Bundle();
bundle.putSerializable("list",courses);
bundle.putString("complete",completed);
returnIntent.putExtras(bundle);
setResult(Activity.RESULT_OK,returnIntent);
super.onBackPressed();
}
}
Please provide a Minimal, Complete, and Verifiable example. Please look at guide how do I ask a good question?
– Andrzej Ziółek
Jul 1 at 11:01
Shared the code. Is this sufficient ?
– Gaurav Mewara
Jul 1 at 13:12
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Please share your code.
– user8035311
Jul 1 at 10:55