getextra from intent android code example

Example 1: 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);
    }
});

Example 2: activity get extras

String id = intent.getStringExtra("id");
String name = intent.getStringExtra("name");

Example 3: get requestcode from intent android

getIntent().getAction();

Example 4: activity get extras

Intent intent = getIntent();

Tags:

Java Example