0

In the main activity there is a fragment that has RecyclerView. When a user clicks an item in the RecyclerView, I am calling ((Activity)v.getContext()).startActivityForResult(intent, Config.REQUEST_ATTENDEES) from my adapter and I handled this request on my onActivityResult method in my main acitivity. And inflate fragment again from onActivityResult. My onActivityResult get triggered but after get triggered, my main activity calls onDestroy. Here below are resources that I looked:

can we call startActivityForResult from adapter?

onActivityResult no longer being called after onDestroy

I'm thinking second one can be my problem but I'm not sure because in my adapter, (Activity)v.getContext() should be my main activity. Any suggestion would be nice.

Community
  • 1
  • 1
melomg
  • 737
  • 3
  • 20
  • 39
  • Yeah it may be possible that your context is not reference of current activity. Please check your **RecyclerView** adapter constructor that you are passing correct context from fragment or not? – Dhruv Jun 02 '16 at 07:00

1 Answers1

0

you can try this: getActivity().startActivityResult(intent,Configs.REQUEST_ATTENDEES)

  • I can't call getActivity() in `viewHolder.getCv().setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //I start activity here for result } });` – melomg Jun 02 '16 at 07:37