Raw service with bindings

Categories: ANDROID like

public class Request2Service extends Service { public static final int MSG_REGISTER_WATCHER = -1; public static final int MSG_UNREGISTER_WATCHER = -2; private ArrayList<Messenger> clients = new ArrayList<>(); private Messenger clientMessenger = new Messenger(new Handler() { @Override public void handleMessage(Message msg) { switch (msg.what) { case MSG_REGISTER_WATCHER: if (!clients.contains(msg.replyTo)) { clients.add(msg.replyTo); } break; case MSG_UNREGISTER_WATCHER: if (clients.contains(msg.replyTo)) […]

TIL: difference between service vs/and intentService

Categories: ANDROID like

Source: http://stackoverflow.com/questions/15524280/service-vs-intentservice Tejas Lagvankar wrote a nice post about this subject. Below are some key differences between Service and IntentService. When to use? The Service can be used in tasks with no UI, but shouldn’t be too long. If you need to perform long tasks, you must use threads within Service. The IntentService can be […]

Working example POST in android

Categories: ANDROID like

Here is another short (IMHO) example how to post in android app. private void postSms(String text) { URL url; HttpURLConnection urlConnection = null; try { url = new URL("http://yourserver.com/sendsms"); urlConnection = (HttpURLConnection) url.openConnection(); urlConnection.setRequestMethod("POST"); urlConnection.setDoOutput(true); List<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair("sms", text));//POST param as "sms" OutputStream os = urlConnection.getOutputStream(); BufferedWriter writer = new BufferedWriter(new […]