0

Here I am Opening the URL which is fetched from JSON Feed in the Browser. I need to open the URL in Another new activity's webview. I Created New Activity where I kept webview too. But the Intent is not passing the String

Here is the Current Code of Opening the URL in Browser

@Override
public void onBindViewHolder(CourseViewHolder holder, int position) {

    final Course course = courseList.get(position);
    holder.textViewCoursename.setText(course.getCoursename());
    holder.textViewcoursedescshort.setText(course.getCoursedescshort());
    holder.textViewcourserating.setText(course.getCourserating());

    Glide.with(context).load(course.getCourseimg()).into(holder.imageView);    

    holder.itemView.setOnClickListener(new Button.OnClickListener() {
        public void onClick(View v) {
            Intent i = new Intent(Intent.ACTION_VIEW);
            i.setData(Uri.parse(course.getCourseurl()));
            context.startActivity(i);
        }
    });
}
Komal12
  • 3,340
  • 4
  • 16
  • 25
MC Naveen
  • 440
  • 5
  • 17

1 Answers1

0

You need to use i.putExtra(KEY, yourURL) instead of i.setData. You will need a key for that value.

And you will get it by the key in the new activity :

String url = (String) getIntent().getExtras().get(KEY);
Ben-J
  • 1,084
  • 8
  • 24
  • Where I have to Mention KEY Value in my Current Activity? – MC Naveen Jan 15 '18 at 17:10
  • KEY value is a string to know what you are passing throught the intent, juste use for example "course_url". More info there : https://stackoverflow.com/questions/2091465/how-do-i-pass-data-between-activities-in-android-application – Ben-J Jan 15 '18 at 17:11
  • I'm getting this error.. I Attached the Image too.. https://imgur.com/a/hl9po `Error:(61, 27) error: no suitable constructor found for Intent(CourseAdapter,Class) constructor Intent.Intent(String,Uri) is not applicable (argument mismatch; CourseAdapter cannot be converted to String) constructor Intent.Intent(Context,Class>) is not applicable (argument mismatch; CourseAdapter cannot be converted to Context)` – MC Naveen Jan 15 '18 at 17:21
  • Here is the Code of WebActivity.java .. https://imgur.com/a/LyQYo – MC Naveen Jan 15 '18 at 17:22
  • It is clear, the constructor need a context as first argument, your coursadapter is not one. You need to use your current activity, like MainActivity.this. – Ben-J Jan 17 '18 at 08:31