I am new in android. I made an app in which two buttons are there one is start_tracking and it will ask for how many hours you want to track. and other button is show_history in which it will show whatever u tracked. But I stuck in one place in which,if I want to track again and after that if I want to see history again it will delete the previous record and show the latest one.
import android.app.IntentService;
import android.content.ContentValues;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.location.Location;
import android.location.LocationManager;
import android.util.Log;
import com.example.ashwani.abcd.db.MyDatabase;
import com.google.android.gms.location.LocationResult;
import java.util.List;
public class LocationIntentService extends IntentService {
public static final String TAG = LocationIntentService.class.getSimpleName();
private LocationManager mLocationManager;
public LocationIntentService() {
super("LocationIntentService");
}
@Override
protected void onHandleIntent(Intent intent) {
if (LocationResult.hasResult(intent)) {
LocationResult result = LocationResult.extractResult(intent);
List<Location> locations = result.getLocations();
for (Location location : locations) {
Log.i(TAG,"location is"+ location.getLatitude()+ "," +location.getLongitude());
MyDatabase myDb = new MyDatabase(this);
SQLiteDatabase db = myDb.getWritableDatabase();
db.insert(MyDatabase.TABLE_NAME, null, getContentValues(location));// here I am inserting the records
}
}
}
private ContentValues getContentValues(Location location) {
ContentValues contentValues = new ContentValues();
contentValues.put(MyDatabase.TIME, location.getTime());
contentValues.put(MyDatabase.LAT, location.getLatitude());
contentValues.put(MyDatabase.LNG, location.getLongitude());
return contentValues;
}
}
Aucun commentaire:
Enregistrer un commentaire