当我尝试在片段中调用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;
}
});
答案 0 :(得分:1)
您使用
getActivity().getIntent()
而不是
getIntent()
答案 1 :(得分:0)
Bundle bundle=getArgument();
如果您已经意图传递了捆绑包。