0

I am developing the android application to get user activity in the background. Here is my code

public class ActivityRecognitionService extends IntentService implements GooglePlayServicesClient.ConnectionCallbacks,GooglePlayServicesClient.OnConnectionFailedListener {

AbstractWrapper w = null;

private PendingIntent pIntent;

private VSensorConfig config = null;

private ActivityRecognitionClient arclient;
private static final String DATE_FORMAT_PATTERN = "yyyy-MM-dd HH:mm:ss.SSSZ";

private static final String LOG_DELIMITER = ";;";

private SimpleDateFormat mDateFormat;


public ActivityRecognitionService() {
    super("ActivityRecognitionIntentService");
}

@Override
protected void onHandleIntent(Intent intent) {

    Bundle b = intent.getExtras();
    config = (VSensorConfig) b.get("config");


try {
        mDateFormat = (SimpleDateFormat) DateFormat.getDateTimeInstance();
    } catch (Exception e) {
    }

    mDateFormat.applyPattern(DATE_FORMAT_PATTERN);
    mDateFormat.applyLocalizedPattern(mDateFormat.toLocalizedPattern());

    int resp =GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
           arclient = new ActivityRecognitionClient(this, this, this);
           arclient.connect();

    if (ActivityRecognitionResult.hasResult(intent)) {


        ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent);
        Log.i("Activity Recived :DDDD", getType(result.getMostProbableActivity().getType()) +"\t" + result.getMostProbableActivity().getConfidence());
        DetectedActivity mostProbableActivity = result.getMostProbableActivity();
        Double confidence = (double) mostProbableActivity.getConfidence();
        Double activityType = (double) mostProbableActivity.getType();



        for (InputStream inputStream : config.getInputStreams()) {
            for (StreamSource streamSource : inputStream.getSources()) {
                w = streamSource.getWrapper();
                break;
            }
            break;
        }

        ((AndroidActivityRecognitionWrapper) w).getLastKnownData();
    }
}

private boolean activityChanged(int currentType) {
    return false;

}




@Override
public void onConnectionFailed(ConnectionResult arg0) {
    // TODO Auto-generated method stub

}

@Override
public void onConnected(Bundle arg0) {
    Intent intent = new Intent(this, ActivityRecognitionService.class);
    pIntent = PendingIntent.getService(this, 0, intent,PendingIntent.FLAG_UPDATE_CURRENT);
    arclient.requestActivityUpdates(1000, pIntent);   
}

@Override
public void onDisconnected() {
    // TODO Auto-generated method stub

}

}

The problem is that Android.os.HandleThread class call starts this intent without the extravalue so I got nullPointerException. Can anyone help me with that?

ida
  • 1,011
  • 1
  • 9
  • 17
  • what HandlerThread? what Intent? – pskink Aug 12 '14 at 08:54
  • I have printed the stack trace and find out that my class is not in the trace and the frist Obj in stack is for Android.os.HandleThread. – ida Aug 12 '14 at 09:39
  • I got the config for null but I have set it when ever I call the service – ida Aug 12 '14 at 09:40
  • tried to Log.d the intent in onHandleIntent? – pskink Aug 12 '14 at 09:52
  • @pskink what do you mean by that? – ida Aug 13 '14 at 15:19
  • If you mean if I log stack trace yes I did and there is none of my functions, only android.os functions in the stack – ida Aug 13 '14 at 15:20
  • Log.d(TAG, "onHandleIntent " + intent) – pskink Aug 13 '14 at 15:27
  • @pskink I did. the strange thing is that this command is executing 2 times while I call it once. And both time it printed that it has extras. But the second time I got null pointer exception – ida Aug 14 '14 at 14:13
  • i don't get it: you say that in both cases it logs that intent has extras but in second case if you call intent.getExtras() it returns null? how come? – pskink Aug 15 '14 at 05:01
  • It has extras with different sizes and I have the following code in which config get the null during the second call. Bundle b = intent.getExtras(); config = (VSensorConfig) b.get("tinygsn.beans.config"); – ida Aug 15 '14 at 09:40
  • tried setIntentRedelivery(false)? – pskink Aug 15 '14 at 09:51
  • the default value for that is false. isn't it? – ida Aug 15 '14 at 10:51

0 Answers0