0

I have an application with three activities. FirstActivity, SecondActivity, ThirdActivity.

In FirstActivity there is a button, which starts SecondActivity. In SecondActivity, there are two ways to go to the ThirdActivity. But there is one method with a code:

    Intent intent = new Intent(SecondActivity.this, ThirdActivity.class);
    finish();
    startActivity(intent);

Both variants use this code snippet.

  1. This code runs in a +- 12 seconds automatically
  2. In onBackPressed() method

And here is my problem: when user press Back, ThirdActivity opens, but in a few seconds ThirdActivity opens again from the first variant.

So, how to fully kill an Activity, so it won't start another activity for two times?

Laughing_Man
  • 179
  • 16

2 Answers2

0

I'm not sure but try calling finish() after starting the activity maybe that will help I'm not sure though like this:

 Intent intent = new Intent(SecondActivity.this, ThirdActivity.class);
 startActivity(intent);
 finish();
Long Luong
  • 764
  • 2
  • 14
  • 28
Brandon
  • 146
  • 8
0

You should cancel your future task if you not need it anymore with

handler.removeCallbacks(yourRunnable)

When you start ThirdActivity from onBackPressed instead handler

Amir K. Zarini
  • 140
  • 1
  • 5