How to open YouTube video link in android app

0 votes

How to open a YouTube link, and then when it opens in the app, it should close the YouTube app and again call my Main Activity which opens the YouTube app. It should however open the YouTube app from scratch and not show the previous YouTube Activity in background.

Main Activity --> Second Activity --> YouTube --> Third Activity --> YouTube

But I want the YouTube app to load again from scratch. But currently, I am getting the previously opened YouTube app which was in the background.

MainActivity

Intent intent = new Intent(MainActivity.this,ThirdActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
finish();

SecondActivity

startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(link)));
sleep(10000);
Intent intent=new Intent(getApplicationContext(),ThirdActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
finish();

ThirdActivity

sleep(5000);
Toast.makeText(getApplicationContext(),"third",Toast.LENGTH_SHORT).show();
Intent intent=new Intent(getApplicationContext(),SecondActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
finish();
I want to load it from scratch, but it's showing me the state where it was paused.
May 31, 2022 in Others by polo
• 1,480 points
790 views

1 answer to this question.

0 votes

The below code will do that:

Intent intent = new Intent(Intent.ACTION_VIEW, "your youtube url here"); startActivity(intent);

if you want to load the url in your activity give a webview and run the url 

answered Jun 1, 2022 by nisha
• 2,190 points

Related Questions In Others

0 votes
0 answers

How to open a new tab or a new window while writing an exam in AI - Onlime Remote Proctored

How to open a new tab or ...READ MORE

Jul 20, 2020 in Others by vimalkamal
• 120 points
2,587 views
0 votes
1 answer

How to create a Volume Icon in Flutter App?

Hi@akhtar, You can use Icon Widget to create ...READ MORE

answered Jul 24, 2020 in Others by MD
• 95,420 points
1,160 views
0 votes
1 answer

How to add one image in Flutter App?

Hi@akhtar, You can use Image.network() method to add ...READ MORE

answered Jul 24, 2020 in Others by MD
• 95,420 points
284 views
0 votes
1 answer

How to create a navigation bar in Flutter app?

Hi@akhtar, To add a drawer to the app, ...READ MORE

answered Aug 25, 2020 in Others by MD
• 95,420 points
450 views
0 votes
1 answer

Android YouTube app Play Video Intent

The best way to run videos on ...READ MORE

answered Jun 6, 2022 in Others by nisha
• 2,190 points
341 views
0 votes
1 answer

How to open the Google Play Store directly from my Android application?

By using developer.andriod.com, one can solve this ...READ MORE

answered Feb 8, 2022 in Others by Rahul
• 9,670 points
127 views
0 votes
1 answer

Launching Google Maps Directions via an intent on Android

We can open Google Maps app using ...READ MORE

answered Jun 1, 2022 in Others by nisha
• 2,190 points
474 views
0 votes
1 answer

How to make android phone flashlight blink?

This might be too fast to blink:- String[] ...READ MORE

answered Jun 6, 2022 in Others by nisha
• 2,190 points
282 views
0 votes
1 answer
0 votes
1 answer

I am not able to Autoplay youTube video in android chrome

It will play if you set it to ...READ MORE

answered Jun 6, 2022 in Others by nisha
• 2,190 points
570 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP