public class CallMonitorService extends Service { @Override public int onStartCommand(Intent intent, int flags, int startId) { Notification notification = new Notification(icon, "service", System.currentTimeMillis()); Intent notificationIntent = new Intent(this, Main.class); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); notification.setLatestEventInfo(this, "title", "text", pendingIntent); notification.flags |= Notification.FLAG_NO_CLEAR; startForeground(1337, notification); new ListenThread().start(); } } class ListenThread extends Thread { public void run() { Looper.prepare(); Handler handler = new Handler() { public void handleMessage(Message msg) { BufferedReader in = null; Socket socket = new Socket(); socket.setKeepAlive(true); socket.connect(new InetSocketAddress(InetAddress.getByName("http://fritz.box"), 1012), 30*1000); in = new BufferedReader(new InputStreamReader(socket.getInputStream()), 8 * 1024); String line = null; while ((line = in.readLine()) != null) { Log.d("TAG", line); } } }; handler.sendEmptyMessage(0); Looper.loop(); } }