In my project i have a **TCP Server** that make a sound a vibrate after a **TCP Client** send a package to it, but now i want that if the counter from the **TCP Server** is **!= 0 after 60 seconds** repeat the sound and vibration but i don't know how to implement that ***IF*** function that controll if the counter is changed after 60 seconds.
Probably there is a simple solution but i'm new in android.

Here is my **Server.java** *code*:

```
public class Server {
DataBaseHandler myDB;
allert Allert;
MainActivity activity;
RecyclerViewAdapter adapterView;
Adapter adapter;
ServerSocket serverSocket;
public static int count=0;
String letto = "";
private SharedPreferences prefs;
static final int socketServerPORT = 8080;

public Server(MainActivity activity) {
    this.activity = activity;
    Thread socketServerThread = new Thread(new SocketServerThread());
    socketServerThread.start();
}

public int getPort() {
    return socketServerPORT;
}

public void onDestroy() {
    if (serverSocket != null) try {
        serverSocket.close();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

private class SocketServerThread extends Thread {
    Vibrator vibrator;
    String date,ora;
    long[] pattern = {0, 1000, 500, 1000, 500, 1000};

    int lun;

    @Override
    public void run() {
        InputStream leggi;
        try {

            serverSocket = new ServerSocket(socketServerPORT);

            while (true) {
                myDB = DataBaseHandler.getInstance(activity);

                Socket socket = serverSocket.accept();
                leggi = socket.getInputStream();
                byte[] data = new byte[1000];
                lun = leggi.read(data, 0, data.length);
                letto = new String(data, "UTF-8");
                count++;
                MediaPlayer mPlay = MediaPlayer.create(activity, R.raw.gabsuono);
                mPlay.start();

                vibrator = (Vibrator) activity.getSystemService(VIBRATOR_SERVICE);
                vibrator.vibrate(pattern, -1);

                date = new SimpleDateFormat("dd-MM-yyyy").format(new Date());
                ora = new SimpleDateFormat("HH:mm:ss").format(new Date());
                myDB.insertDataServer(date, ora, letto);

                        activity.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {

                        allert.refreshing.setVisibility(View.VISIBLE);
                        prefs = activity.getSharedPreferences("MY_DATA", MODE_PRIVATE);
                        SharedPreferences.Editor edit = prefs.edit();
                        edit.putInt("counter", count);
                        edit.commit();
                        MainActivity.msg.setText(String.valueOf(count));
                        MainActivity.msg.setVisibility(View.VISIBLE);

                    }
                });
                leggi.close();

            }
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();

        }

    }

}

public void Parti() {
    prefs = activity.getSharedPreferences("MY_DATA", MODE_PRIVATE);
    count = prefs.getInt("counter", count);
    MainActivity.msg.setText("" + count);
    if (count == 0)
        MainActivity.msg.setVisibility(View.INVISIBLE);
    else
        MainActivity.msg.setVisibility(View.VISIBLE);

    }

}

```