Note that there are some explanatory texts on larger screens.

plurals
  1. POandroid keep the app running
    primarykey
    data
    text
    <p>i have this code that detects your walking speed and it records the latitude and longitude and your walking speed or if your standing not walking in an sqlite tabel then it should call the table and send them to a server using httpconnect </p> <p>for some reason its not sending the info to the server and also it crashes after a while what is causing the problem and i read somewhere online that i should make the code as a service can you please tell me how to fix the code and is there any problems with the timer</p> <p>Note: I have no errors in the code</p> <p>thank you in advance</p> <pre><code> class WalkingData{ public double lng=0.0; public double lat=0.0; public long gpsTime=0; public double Walking=0.0; public WalkingData (double ilng, double ilat, long iGPSTime, double iWalking){ lng=ilng; lat=ilat; gpsTime=iGPSTime; Walking=iWalking; } } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); LocationManager locationManager; String context = Context.LOCATION_SERVICE; locationManager = (LocationManager) getSystemService(context); Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setAltitudeRequired(false); criteria.setBearingRequired(false); criteria.setCostAllowed(true); criteria.setPowerRequirement(Criteria.POWER_LOW); String provider = locationManager.getBestProvider(criteria, true); Location location = locationManager.getLastKnownLocation(provider); updateWithNewLocation(location); locationManager.requestLocationUpdates(provider, 2000, 10, locationListener); } private final LocationListener locationListener = new LocationListener() { public void onLocationChanged(Location location) { updateWithNewLocation(location); } public void onProviderDisabled(String provider) { updateWithNewLocation(null); } public void onProviderEnabled(String provider) { } public void onStatusChanged(String provider, int status, Bundle extras) { } }; private void updateWithNewLocation(Location location) { String latLongString; TextView myLocationText; myLocationText = (TextView) findViewById(R.id.myLocationText); //String addressString = "No address found"; if (location != null) { double lat = location.getLatitude(); double lng = location.getLongitude(); latLongString = "Lat:" + lat + "\nLong:" + lng; MyWalk =(double)location.getSpeed(); MyGPSTime = location.getTime(); long currentTimestamp = System.currentTimeMillis(); myLocationText.setText("Your Current Walk: " + (MyWalk) +"\nYour Current Position is: " + latLongString + "\n" + "Time is: " + currentTimestamp+"\n\n"); trakingWalking (MyWalk, lat, lng, MyGPSTime); } else { latLongString = "No location found"; } } public void trakingWalking (double Walking, double lat, double lng, long GPSTime) { final double ChangedWalking = Walking; final double ChangedLat = lat; final double ChangedLng = lng; final long ChangedGPSTime = GPSTime; Timer updateTimer = new Timer("pedometer"); updateTimer.scheduleAtFixedRate(new TimerTask() { public void run() { checkWalking(ChangedWalking, ChangedLat, ChangedLng, ChangedGPSTime); } }, 0, WalkingSampleRate); } private void checkWalking( double ChangedWalking1, double ChangedLat1, double ChangedLng1, long ChangedGPSTime1) { final double ChangedWalking2 = ChangedWalking1; final double ChangedLat2 = ChangedLat1; final double ChangedLng2 = ChangedLng1; final long ChangedGPSTime2 = ChangedGPSTime1; WalkingHandler.post(new Runnable() { public void run() { if(WalkingState==0){ //TODO Log.v("log_tag", "+-+-+-+-+-+-+-+-+- you are standing"); } //state = 0 else(WalkingState==1){ StoreWalking(); Sticket(); } } }); } public void Sticket(){ Log.v("log_tag", "???????????????????????????????? Sticket()"); elhgsdatabase db = new elhgsdatabase(this); db.open(); z = db.getAllTitles(); //narrow down to 20 last seconds if (z.moveToFirst()) { do { SticketFunction(); } while (z.moveToNext()); } db.close(); } public void SticketFunction(){ //HttpClient HttpClient WalkingWalking = new DefaultHttpClient(); //Response handler ResponseHandler&lt;String&gt; res = new BasicResponseHandler(); HttpPost postMethod = new HttpPost("www.some-site.com"); try { List&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;(5); //Walking nameValuePairs.add(new BasicNameValuePair("Walking", z.getString(1)+"")); //Longitude nameValuePairs.add(new BasicNameValuePair("lat", z.getString(2)+"")); //Latitude nameValuePairs.add(new BasicNameValuePair("lon", z.getString(3)+"")); //GPS Time nameValuePairs.add(new BasicNameValuePair("GPSTime", z.getString(4)+"")); //Encode and set entity postMethod.setEntity(new UrlEncodedFormEntity(nameValuePairs, HTTP.UTF_8)); //Execute String response = WalkingWalking.execute(postMethod, res).replaceAll("&lt;(.|\n)*?&gt;",""); if (response.equals("Done")){ //Log.v("log_tag", "!!!!!!!!!!!!!!!!!! SticketFunction got a DONE!"); } else Log.v("log_tag", "!!!!!!!?????????? SticketFunction Bad or no response: "); } catch (ClientProtocolException e) { // TODO Auto-generated catch block //Log.v("log_tag", "???????????????????? SticketFunction Client Exception"); } catch (IOException e) { // TODO Auto-generated catch block //Log.v("log_tag", "???????????????????? IO Exception"); } } /* * */ public void StoreWalking(){ long idy; elhgsdatabase db = new elhgsdatabase(this); db.open(); while (!WalkingLog.isEmpty()) { WalkingData tmp = WalkingLog.poll();// .pollFirst(); //TODO: insert log_cat markups here idy = db.insertWalkingInfo( tmp.Walking, tmp.lat, tmp.lng, tmp.gpsTime); } db.close(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload