当前位置: 动力学知识库 > 问答 > 编程问答 >

android - How to getIntent().getData(); on Fragment

问题描述:

On my application is use login with twitter, in example code work in Activity

but my app use work in Fragment

  1. Click login with twitter button
  2. Go to web browser for Authorize application
  3. Back to application Feeds(use fragment) & show Toast twitter_id

How to edit error on Uri uri = getIntent().getData();

@Override

public View onCreateView(LayoutInflater inflater, ViewGroup container,

Bundle savedInstanceState) {

View rootView = inflater.inflate(R.layout.fragment_feed, container, false);

**Uri uri = getIntent().getData();**

String verifier = uri.getQueryParameter(ConstantValues.URL_PARAMETER_TWITTER_OAUTH_VERIFIER);

TwitterGet get=new TwitterGet();

get.execute(verifier);

return rootView;

}

网友答案:

Use Uri uri = getIntent().getData(); in the fragment, you just need call getActivity() first:

Uri uri = getActivity().getIntent().getData();
网友答案:

When instantiating the fragment pass your extra with a key

In your fragment extract that extra by identifying with a key.For example

Bundle args = getActivity().getIntent().getExtras();
String value= args.getString("your key");
分享给朋友:
您可能感兴趣的文章:
随机阅读: