Pendingintent.getservice is not working properly

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) {
            // TODO Auto-generated method stub




                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) {
        // Toast.makeText(this, "in service", Toast.LENGTH_LONG).show();
        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();
        }
+4
source share
1 answer

The answer may be on this page ("Change location settings on Android 4.4"): https://support.google.com/nexus/answer/3467281

, Android 4.4 ( ), . , , . 4.4.

+2

Source: https://habr.com/ru/post/1531171/


All Articles