I am trying to start a service using pendingintent, and that is how I am trying
btnSave.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
InfoLayout.setVisibility(LinearLayout.VISIBLE);
mIntentService = new Intent(MainActivity.this, LocationService.class);
mPendingIntent = PendingIntent.getService(
MainActivity.this, 1, mIntentService, 0);
locationrequest = LocationRequest.create();
locationrequest.setInterval(10000 * 6);
locationClient.requestLocationUpdates(locationrequest,
mPendingIntent);
Toast.makeText(MainActivity.this, "Starting service",
Toast.LENGTH_SHORT).show();
}
});
I tried this code on 2.3.5 and it works great, but when I tried this code on 4.4.2, my service does not start at all. I do not understand why this is happening. can someone explain what i am doing wrong.
Thanks in advance:)
EDIT
public void onStart(Intent intent, int startId) {
Location location = intent
.getParcelableExtra(LocationClient.KEY_LOCATION_CHANGED);
db = new PhoneDatasource(this);
db.open();
contactlist = db.getAllContacts();
db.close();
if (location != null) {
add = null;
Constants.latitude = location.getLatitude();
Constants.longitude = location.getLongitude();
}
source
share