-1

I'm passing an url as string from Fragment to Activity. But I'm getting an error of could resolve getArguments() and it is highlighted in red color

Inside Fragment

 Intent i = new Intent(getActivity(), web.class);
            Bundle args1 = new Bundle();
            args1.putString("url1", "file:///android_asset/em/japan.html");
            startActivity(i);
            ((Activity) getActivity()).overridePendingTransition(0,0);

and inside activity where I want to receive string, I've used

String url1 = getArguments().getString("url1");`

But getArguments() is highlighted in red color.

Thanks in advance.

Abhishek kumar
  • 4,326
  • 8
  • 25
  • 43
BlueYeti81
  • 67
  • 10

2 Answers2

0

You need a callback for that, see this: https://developer.android.com/training/basics/fragments/communicating.html

comment below if you need do a sample project for your case :D

Tuấn Kiệt
  • 312
  • 3
  • 13
0
    Intent i = new Intent(getActivity(), web.class);
    i.putExtra("url1", "file:///android_asset/em/japan.html");
    startActivity(i);

and in your activity use

 String url1 = getIntent().getStringExtra("url1");
Clapa Lucian
  • 560
  • 1
  • 7
  • 14
  • it removes the error but don't load anything....now activity appears empty. – BlueYeti81 Feb 17 '18 at 17:46
  • Well, did you store that value in some variable and checked it.s value? – Clapa Lucian Feb 17 '18 at 18:03
  • Instead I used this in frgament intent.putExtra("url", "http://saptahik.ekantipur.com/") and on activity I used this String url = getIntent().getStringExtra("url"); and It worked for me.Thanks anyways. – BlueYeti81 Feb 18 '18 at 00:48