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.