0

I am working on user activity tracking application.

I have used the Activity Recognition API to track the user activity.

I have set the Intent service to be called to get the user activity at specified interval for example every 20 seconds.

Below is my Activity recognition intent service class :

/**
 * Called when a new activity detection update is available.
 */
@Override
protected void onHandleIntent(Intent intent) {   
   // mPId = intent.getStringExtra("PID");

--- When I send some data by put extra along with pending intent here i am not getting the user activity intent data. The User activity intent data is replaced by my data

    // If the intent contains an result data
    if (ActivityRecognitionResult.hasResult(intent)) {
        // Get the update
        ActivityRecognitionResult result = ActivityRecognitionResult
                .extractResult(intent);

        // Log the update
        saveActivityRecognitionResult(result);
    }
}

The above code working fine If I have not passed any own data.

I want to send some data along with this intent. I set that data along with pending intent. But If I set the data I am received only that data not the user activity intent data.

I don't want to to use the shared preference to store and fetch it inside of intent service wont work out.

Please help me to solve this issue.

M Vignesh
  • 1,586
  • 2
  • 18
  • 55

1 Answers1

0

I'd not pass this intent further but take data in your onHandleIntent and add it to other intent.

I assume you're trying to pass this intent to some service which stores activity data in sqlite or something... there's a catch.

Don't use IntentService, because before or during it's doing its job phone may go asleep if you will not acquire WakeLock. Get familiar with WakefulBroadcastReceiver to deal with it.

The other solution is to just use BroadcastReceiver as it's guaranteed phone will not go asleep.

Marian Paździoch
  • 8,813
  • 10
  • 58
  • 103