片段内的getIntent()

时间:2017-01-30 08:09:09

标签: java android

当我尝试在片段中调用intent时,我得到"无法解析方法getIntent()"。

这是我的代码

@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;
        }
    });

2 个答案:

答案 0 :(得分:1)

您使用

getActivity().getIntent()

而不是

getIntent()

答案 1 :(得分:0)

Bundle bundle=getArgument(); 

如果您已经意图传递了捆绑包。