fragment get intent android code example

Example 1: get intent not working in fragment

// add the getActivity() before getIntent and it should work perfectly 
// inside your fragment
Bundle bundle = getActivity().getIntent().getExtras();

Example 2: intent in fragment android

Button button = (Button) rootView.findViewById(R.id.button1);
button.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        Intent intent = new Intent(getActivity(), AnotherActivity.class);
        startActivity(intent);
    }
});

Tags:

Java Example