okay here is my problem
ApprovalCutiCardAdapter
) that hold the content.Inside that ApprovalCutiCardAdapter
I set OnClickListener on the card, when Card is clicked it will launch an Activity called DetailApprovalCuti
. Here is my code to launch the activity
((Activity) MyApplication.getmContext()).startActivityForResult(detailApprovalCutiIntent, 1);
In DetailApprovalCuti
I'm executing finishActivity(1)
to get an event of onActivityResult
. But that event is not being called everywhere (in Activity that host the fragment, and in the fragment)
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.e("result", "ApprovalIzinCutiFragment");
super.onActivityResult(requestCode, resultCode, data);
}
Here's my code to start the Acvitity
@Override
public void onBindViewHolder(final CutiViewHolder holder, final int position) {
....
holder.cv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent detailApprovalCutiIntent = new Intent(MyApplication.getmContext(), DetailApprovalCuti.class);
Bundle b = new Bundle();
b.putParcelable("cuti", ApprovalCutiCardAdapter.allCuti.get(position));
b.putParcelable("process_cuti", ApprovalCutiCardAdapter.allCuti.get(position).getProcessCuti());
detailApprovalCutiIntent.putExtras(b);
((Activity)MyApplication.getmContext()).startActivityForResult(detailApprovalCutiIntent,1);
}
});
....
}
Here's my code to finish the activity
btnReject.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
new AlertDialog.Builder(DetailApprovalCuti.this)
.setTitle("Peringatan")
.setMessage("Apakah anda yakin?")
.setIcon(android.R.drawable.ic_dialog_alert)
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
setResult(1);
finish();
}
}).setNegativeButton(android.R.string.no, null).show();
}
});
The problem is that, in the following line, you're calling startActivityForResult()
from an Activity which might not be the one you're expecting.
((Activity)MyApplication.getmContext()).startActivityForResult(detailApprovalCutiIntent, 1);
Considering that your adapter is set from a Fragment
, you should modify the above line to:
fragment.getActivity().startActivityForResult(detailApprovalCutiIntent, 1);
Never use singletons, for Singletons are Pathological Liars.
PS: single instances are fine but singletons (like global variables) are a bad design and must be avoided.