Я ищу способ остановить/убить нить, я видел, что Thread.stop() устарел. Поэтому я начал искать другое решение и видел несколько сообщений, предполагающего это:ищет способ остановить/убить нить
thread.interrupt();
thread = null;
Но это просто не остановит мою тему, моя тема выглядит следующим образом:
public static Thread loadingSpinnerTimer (final Context context, final ImageView imageView){
final Handler mHandler = new Handler();
thread = new Thread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
while (!isPaused) {
try {
Thread.sleep(100);
mHandler.post(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
// Write your code here to update the UI.
Log.e("ThreadMessage","HasRun");
if (ticker == 12){
ticker = 0;
}
Bitmap myBitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.spinner_160x160);
Bitmap img = Bitmap.createBitmap(myBitmap.getWidth(), myBitmap.getHeight(), Bitmap.Config.ARGB_8888); //ARGB_8888 transparrent?
Canvas canvas = new Canvas(img);
int offset = myBitmap.getWidth()*ticker;
Rect srcrectangle = new Rect(0, offset, myBitmap.getWidth(), myBitmap.getWidth()+offset);
Rect dstrectangle = new Rect(0, 0, myBitmap.getWidth(), myBitmap.getWidth());
canvas.drawBitmap(myBitmap,srcrectangle,dstrectangle,null);
img.setHeight(myBitmap.getWidth());
imageView.setImageDrawable(new BitmapDrawable(context.getResources(), img));
ticker++;
}
});
} catch (Exception e) {
// TODO: handle exception
}
}
}
});
thread.start();
return thread;
}
Любых получить решение я могу использовать, чтобы остановить/убить мою тему? Буду признателен за любую оказанную помощь.
чек [ oracle docs] (http://docs.oracle.com/javase/tutorial/essential/concurrency/interrupt.html) – TheLostMind
см. это [ссылка] (http://stackoverflow.com/a/20528033/4101719) – coderhyme