I am a beginner in the Android Development.I want to make an android app which sends the GPS and network locations (lat & long) to my server (static IP). I have found th
Your problem is that
public void onClick(View v) {
postData(lat, lon);
}
runs on the UI thread. It means that while you do the "post" action, the UI isn't refreshed and cannot be accessed - your app get stuck until the post ends.
You need to do something like:
public void onClick(View v) {
PostAsyncTask postAsyncTask = new PostAsyncTask();
postAsyncTask.execute();
}
private class PostAsyncTask extends AsyncTask<URL, Integer, Long> {
protected Long doInBackground(URL... urls) {
postData(lat, lon);
return 0;
}
protected void onPreExecute() {
// show progress dialog
}
protected void onPostExecute(Long result) {
// hide progress dialog
}
}
Move postData
off the main thread to a secondary thread. Look at Async
task for examples here: http://developer.android.com/reference/android/os/AsyncTask.html