Search code examples
androidmultithreadingandroid-activitybackterminate

Does Threads in activity terminates when starting another?


I have an activity that starts 3 threads that make a "While(true)" loop

when i start a new activity, does those threads terminate themselves?

And another question, how do i start a new activity but i don't want to allow the 'back' button to return me to the old activity - actually i want to dispose the first activity and create and show a new one

thank you Ron


Solution

  • when i start a new activity, does those threads terminate themselves?

    No, they don't. You have to stop them before closing your activity.

    how do i start a new activity but i don't want to allow the 'back' button to return me to the old activity

    Just call finish() from your first activity when you start the second one :

    Intent intent = new Intent(...);
    startActivity(intent);
    finish();