100Awesome
100Awesome

Reputation: 37

Unwanted duplicated activity

There is a code that sends an int 'a' from the main activity to activity B. It also starts activity B with the fade animations. However, this code creates 2 of the same activity B's and I only need 1 activity B. How can I fix this so that it only makes 1.

new Handler().postDelayed(new Runnable() {
        public void run() {
            Handler splash = new Handler();
            int a = 1;
            Intent myIntent = new Intent(MainActivity.this, Differentiate.class);
            startActivity(new Intent(MainActivity.this, Differentiate.class));
            myIntent.putExtra("HEADER", a);
            overridePendingTransition(R.anim.fade_in_switch_fast,R.anim.fade_out_switch_fast);
            startActivity(myIntent);
            finish();
        }
    }, secondsDelayed * 2000);

Upvotes: 0

Views: 72

Answers (3)

Ankit Patidar
Ankit Patidar

Reputation: 2781

Hey just remove this line from code:

 startActivity(new Intent(MainActivity.this, Differentiate.class)); 

Rest is fine in your code.

Upvotes: 0

Peyman
Peyman

Reputation: 973

That's because you are starting Activity B twice!

you should remove this part of your code:

startActivity(new Intent(MainActivity.this, Differentiate.class));

Upvotes: 0

Iulian Popescu
Iulian Popescu

Reputation: 2643

You are starting the second activity twice. Remove the following line from your code and move overridePendingTransition after you use the intent to start the activity:

startActivity(new Intent(MainActivity.this, Differentiate.class));

Upvotes: 1

Related Questions