-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,347
  • 8
  • 29
  • 44
BlueYeti81
  • 67
  • 10
  • Just pass an instance of the activity – Zoe Feb 17 '18 at 15:32
  • 1
    Possible duplicate of [Passing Data Between Fragments to Activity](https://stackoverflow.com/questions/14439941/passing-data-between-fragments-to-activity) – ADM Feb 17 '18 at 15:39

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
  • 590
  • 2
  • 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