Im developing and App and I need to pass int data from a fragment to Another Activity. The problem its that it returns 0 or false.
First I start ActivityForResult putting a Bundle. Then I pass a boolean and it works fine but when I try to put the int into the bundle from the fragment and comeback to onActivityResult it retuns 0 or false.
Can someone help please? I have tried with putExtras too and still false
public void newcampeon(View view) {
Intent i = new Intent(getApplicationContext(), Campeones.class);
b = new Bundle();
Boolean vengodraft = true;
b.putBoolean("vengodraft",vengodraft);
i.putExtras(b);
startActivityForResult(i,01);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
int res = b.getInt("idcampeon");
aban1.setImageResource(res);
Toast.makeText(getApplicationContext(),String.valueOf(res),
Toast.LENGTH_SHORT).show();
}
------ Fragment on Another Acivity
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_top_lane, container, false);
b = getArguments();
if(b!=null){
Boolean vengodraft = b.getBoolean("vengodraft");
if(vengodraft==true){
final ImageView aatrox = v.findViewById(R.id.aatrox);
aatrox.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int id = aatrox.getId();
getActivity().setResult(Activity.RESULT_OK);
b.putInt("idcampeon",id);
getActivity().finish();
}
});
}
}
return v;
It should return the current id of the Img