2017-01-30 52 views
0

当我尝试调用片段中的意图时,出现“无法解析方法getIntent()”。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; 
     } 
    }); 

回答

1

您使用

getActivity().getIntent()

,而不是

getIntent() 
0
Bundle bundle=getArgument(); 

如果您在意图通过捆绑。