androidcrowdsourcing

Send data from android app to Server without OnClickListener?


I want to build a system based on crowdsoucing.The android app will gather data about the location of itms and send them to the server. How to post data in android without using onClicklstener? I want the data to be sent in the background automatically


Solution

  • You should create a background thread for that. You can use AsyncTask, or general Java Thread class, or ExecutorService with a Runnable.

    Problem with AsyncTask is that you can't use more than 1 AsyncTask sub-classes until the first one had been destroyed. And automatically destroying it after it's done is a little complicated.

    Instructions on AsyncTask: http://developer.android.com/reference/android/os/AsyncTask.html

    Instructions on Java Thread: http://docs.oracle.com/javase/tutorial/essential/concurrency/runthread.html

    Safer way with ExecutorService: http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ExecutorService.html