-1

I am creating a quiz in my app and after the score has been shown it returns to an activity 'NavigActivity' however I am wondering how i would change this code to return to a fragment which is the second icon in my bottom navigation bar? the fragment I want it to return to is DashboardFragment

Toast.makeText(getApplicationContext(), "Your score: " + percentage + "%", Toast.LENGTH_SHORT).show();

new Handler().postDelayed(new Runnable() {
    @Override
    public void run() {
        Intent i = new Intent(EmotionsActivity.this, NavigActivity.class);
        startActivity(i);
        finish();
    }
}, 3000); // Set your time here //
Vamsi
  • 878
  • 1
  • 8
  • 25
David G
  • 325
  • 1
  • 3
  • 15

1 Answers1

0

Pass an extra from EmotionsActivity.java in the run() method:

new Handler().postDelayed(new Runnable() {
    @Override
    public void run() {
        Intent i = new Intent(EmotionsActivity.this, NavigActivity.class);
        i.putExtra("unique_id", "from_emotions_activity"); 
        startActivity(i);
        finish();
    }
}, 3000); // Set your time here //

and in your NavigActivity onCreate() method:

String fromWhichActivity = getIntent().getStringExtra("unique_id");
if (fromWhichActivity.equals("from_emotions_activity") {
    // perform fragmentTranaction...add/replace....commit
}
Vamsi
  • 878
  • 1
  • 8
  • 25