Hisham Hummadi
Hisham Hummadi

Reputation: 1

getIntent() inside a fragment

When I try to call an intent in a fragment, I get "Cannot resolve method getIntent()".

Here is my code

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
   return inflater.inflate(R.layout.activity_browse_product,null);

    if(getIntent().getBooleanExtra("Exit me", false)){
        finish();
        return; // add this to prevent from doing unnecessary stuffs
    }

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbarBrowse);
    setSupportActionBar(toolbar);

    spnCategory = (Spinner)findViewById(R.id.spinnerCategory);

    spnCategory.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener(){
        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {

        }

        public void onNothingSelected(AdapterView<?> adapterView) {
            return;
        }
    });

Upvotes: 0

Views: 2246

Answers (2)

D.J
D.J

Reputation: 1559

Bundle bundle=getArgument(); 

if you have passed bundle in intent.

Upvotes: 0

Aytek S&#246;kmen
Aytek S&#246;kmen

Reputation: 474

You use

getActivity().getIntent()

instead of

getIntent()

Upvotes: 2

Related Questions