0

I'm using Android Studio 1.3.2

I have this Thread and i start it somewhere else in my code like this:

serverChecksThread.Start();

This is the Thread code:

Thread serverChecksThread = new Thread(new Runnable()
{

    @Override
    public void run()
    {
        Looper.prepare();
        Looper l = Looper.myLooper();
        customHandler = new Handler(l);
        customHandler.postDelayed(serverChecksRunnable, 0);
        Looper.loop();    
    }
});

    Runnable serverChecksRunnable = new Runnable()
    {
        @Override
        public void run()
        {
            if (startuploadstatusthread == true))
            {
                checkServer = Get(iptouse + "uploadstatus");

            }

            Handler h=new Handler(Looper.getMainLooper());
            h.post(new Runnable()
            {
                @Override
                public void run()
                {
                    if (startuploadstatusthread == true))
                    {
                        if (checkServer != null)
                        {
                            String a = null;
                            try
                            {
                                a = new String(checkServer, "UTF-8");
                                textforthespeacch = a;
                                if (textforthespeacch.contains("upload completed"))
                                {
                                    String[] parts = textforthespeacch.split(",");
                                    String varr = parts[0];
                                    String varr1 = parts[1];
                                    String varr2 = parts[2];

                                    textforthespeacch = varr;
                                    status1.setText("Upload completed" + " " + varr1 + "%");
                                    timerValue.setText(varr2);
                                    numberofuploadedfilescounter += 1;
                                    uploadedfilescount.setText(("Uploaded Files: " + numberofuploadedfilescounter));
                                    startuploadstatusthread = false;
                                    MainActivity.this.initTTS();
                                    serverChecksThread.stop();
                                }
                                if (textforthespeacch.contains("uploading"))
                                {
                                    String[] split = textforthespeacch.split(" ");
                                    textforthespeacch = split[0];
                                    status1.setText("Uploading" + " " + split[1] + "%");
                                    servercheckCounter += 1;
                                    if (servercheckCounter == 1)
                                    {
                                        MainActivity.this.initTTS();
                                    }
                                }
                            } catch (UnsupportedEncodingException e)
                            {
                                e.printStackTrace();
                            }
                        }
                    }

                }
            });

            customHandler.postDelayed(serverChecksRunnable,1000);
        }
    };

Inside the Runnable i did:

serverChecksThread.stop();

I didn't test it yet but once i wrote the serverChecksThread.stop(); i see on the stop() a line:

Stop

What this line on the stop mean ?

Daniel van wolf
  • 393
  • 1
  • 5
  • 16
  • This means stop method is deprecated and should not be used as it might be removed from api later in future – Vivek Singh Nov 02 '15 at 18:41
  • refer the [link](http://stackoverflow.com/questions/10961714/how-to-properly-stop-the-thread-in-java) to know how to stop threads. – Vivek Singh Nov 02 '15 at 18:46
  • I would suggest you read the [javadocs](http://docs.oracle.com/javase/7/docs/api/java/lang/Thread.html#stop()) to understand why it is deprecated, and what you should be doing (ideally, the thread should be determining when it can safely stop). – dcsohl Nov 02 '15 at 18:46
  • @Vivek: to nitpick, stop method is likely in no danger of being removed from the API. it is marked deprecated more as a warning not to mess with it unless you know what you're doing. OP: you shouldn't be updating ui components except from the event thread. – Nathan Hughes Nov 02 '15 at 18:52

0 Answers0