I am developing an android application which works on threads How to stop or destroy the thread in android while i was passing to the next activity can any one tell me please i am new to this
Asked
Active
Viewed 121 times
-6
-
Hahaha... so funny i know that but i need a perfect answer dude that's why i am posting here if you know the answer please tell me @MD – dEePU Jun 20 '15 at 11:51
-
You definitely get perfect answer from _Google_. – M D Jun 20 '15 at 11:59
2 Answers
1
In onStop() method, call interrupt as follows:
yourThreadObject.interrupt()
and in the run() method of the thread, have a condition that checks for Thread's interrupt status. Depending on your implementation, you might want to enclose this check within a while loop as,
public void run() {
while (!Thread.interrupted()) {
//do something
...
}
}
or you might check at certain points in the run() method as,
public void run() {
//do something
...
if (Thread.interrupted()) {
return;
}
//do something
...
}

Darshan Dorai
- 659
- 8
- 10
0
and finish() after you call next activity. For eg.,
startActivity(intent);
finish();
Hope it helps

aqel
- 415
- 1
- 5
- 11