I have trouble to return data from fragment to activity.
I have Activity A: is main activity for add product, user when click the text view (selectCategory) this activity show to user activity B which content fragment Bb(all type of Category), when user clicks in some of this categories, the app going to show user activity C which has fragment Cc (subcategories).
Here my problem: I need when the user clicks in some of this subcategory which content in fragment Cc to return data to activity A then show to the user.
A call --> B
categoryTextView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i= new Intent(A.this,B.class);
i.putExtra("fragmenttype","CategoryFragment");
startActivityForResult(i,10);
}
});
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 10) {
if (resultCode == RESULT_OK) {
titleProduct.setText(data.getStringExtra("nodecategory"));
}
}
}
return data from Cc fragment to A but nothing happened (I need from code to go to activity A to catch data in onActivityResult
):
@Override
public void onClick(TreeNode node, Object value) {
Intent i = new Intent();
i.putExtra("nodecategory","hi");
getActivity().setResult(Activity.RESULT_OK, i);
getActivity().finish();
}