Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.prodev.litetrack;
- import java.io.IOException;
- import java.util.ArrayList;
- import java.util.List;
- import org.apache.http.HttpResponse;
- import org.apache.http.NameValuePair;
- import org.apache.http.client.ClientProtocolException;
- import org.apache.http.client.HttpClient;
- import org.apache.http.client.entity.UrlEncodedFormEntity;
- import org.apache.http.client.methods.HttpPost;
- import org.apache.http.impl.client.DefaultHttpClient;
- import org.apache.http.message.BasicNameValuePair;
- import android.app.Service;
- import android.content.Context;
- import android.content.Intent;
- import android.os.AsyncTask;
- import android.os.IBinder;
- import android.os.NetworkOnMainThreadException;
- import android.util.Log;
- public class MainActivity extends Service {
- private LocationServices locationServices;
- private Context context;
- @Override
- public void onCreate() {
- super.onCreate();
- context = this;
- locationServices = new LocationServices(context);
- new LocationWorker().execute(new Boolean[] {true});
- }
- class LocationWorker extends AsyncTask<Boolean, Integer, Boolean> {
- @Override
- protected void onPreExecute() {}
- @Override
- protected void onPostExecute(Boolean result) {
- new InternetWorker().execute(new Boolean[] {true});
- }
- @Override
- protected Boolean doInBackground(Boolean... params) {
- while(locationServices.gotLocation() == false){/*do nothing*/}
- return true;
- }
- }
- class InternetWorker extends AsyncTask<Boolean, Integer, Boolean> {
- @Override
- protected void onPreExecute() {}
- @Override
- protected void onPostExecute(Boolean result) {
- try {
- Thread.sleep(60000);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- new LocationWorker().execute(new Boolean[] {true});
- }
- @Override
- protected Boolean doInBackground(Boolean... params) {
- Log.i("GPS", "Got location.");
- /* write to file here */
- return true;
- }
- }
- @Override
- public IBinder onBind(Intent intent) {
- // TODO Auto-generated method stub
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement