app/src/main/java/com/google/android/gms/fit/samples/basichistoryapifinal/Update.java
private void registerFitnessDataListener(DataSource dataSource, DataType dataType) {
        mListener = new OnDataPointListener() {
            @Override
            public void onDataPoint(DataPoint dataPoint) {
                for (final Field field : dataPoint.getDataType().getFields()) {
                    final Value val = dataPoint.getValue(field);
                    Log.i(TAG, "Detected DataPoint field: " + field.getName());
                    Log.i(TAG, "Detected DataPoint value: " + val);
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {

                            MainActivity.scount = val.asInt();
                            Intent intent = new Intent(Update.this, MainActivity.class);
                            intent.putExtra("usernamesignin", username);
                            Update.this.startActivity(intent);

                        }
                    });
                }
            }
        };

        Fitness.SensorsApi.add(
                mClient,
                new SensorRequest.Builder()
                        .setDataSource(dataSource) // Optional but recommended for custom data sets.
                        .setDataType(dataType) // Can't be omitted.
                        .setSamplingRate(10, TimeUnit.SECONDS)
                        .build(),
                mListener)
                .setResultCallback(new ResultCallback<Status>() {
                    @Override
                    public void onResult(Status status) {
                        if (status.isSuccess()) {
                            Log.i(TAG, "Listener registered!");
                        } else {
                            Log.i(TAG, "Listener not registered.");
                        }
                    }
                });
    }
/*
    Register a listener with the Sensors API.
     */
Register a listener with the Sensors API.
Register a listener with the Sensors API .
private void registerFitnessDataListener(DataSource dataSource, DataType dataType) {
        mListener = new OnDataPointListener() {
            @Override
            public void onDataPoint(DataPoint dataPoint) {
                for (final Field field : dataPoint.getDataType().getFields()) {
                    final Value val = dataPoint.getValue(field);
                    Log.i(TAG, "Detected DataPoint field: " + field.getName());
                    Log.i(TAG, "Detected DataPoint value: " + val);
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            MainActivity.scount = val.asInt();
                            Intent intent = new Intent(Update.this, MainActivity.class);
                            intent.putExtra("usernamesignin", username);
                            Update.this.startActivity(intent);
                        }
                    });
                }
            }
        };
        Fitness.SensorsApi.add(
                mClient,
                new SensorRequest.Builder()
                        .setDataSource(dataSource) 
                        .setDataType(dataType) 
                        .setSamplingRate(10, TimeUnit.SECONDS)
                        .build(),
                mListener)
                .setResultCallback(new ResultCallback<Status>() {
                    @Override
                    public void onResult(Status status) {
                        if (status.isSuccess()) {
                            Log.i(TAG, "Listener registered!");
                        } else {
                            Log.i(TAG, "Listener not registered.");
                        }
                    }
                });
    }
private void registerFitnessDataListener ( DataSource dataSource , DataType dataType ) { mListener = new OnDataPointListener ( ) { @ Override public void onDataPoint ( DataPoint dataPoint ) { for ( final Field field : dataPoint . getDataType ( ) . getFields ( ) ) { final Value val = dataPoint . getValue ( field ) ; Log . i ( TAG , "Detected DataPoint field: " + field . getName ( ) ) ; Log . i ( TAG , "Detected DataPoint value: " + val ) ; runOnUiThread ( new Runnable ( ) { @ Override public void run ( ) { MainActivity . scount = val . asInt ( ) ; Intent intent = new Intent ( Update . this , MainActivity . class ) ; intent . putExtra ( "usernamesignin" , username ) ; Update . this . startActivity ( intent ) ; } } ) ; } } } ; Fitness . SensorsApi . add ( mClient , new SensorRequest . Builder ( ) . setDataSource ( dataSource ) . setDataType ( dataType ) . setSamplingRate ( 10 , TimeUnit . SECONDS ) . build ( ) , mListener ) . setResultCallback ( new ResultCallback < Status > ( ) { @ Override public void onResult ( Status status ) { if ( status . isSuccess ( ) ) { Log . i ( TAG , "Listener registered!" ) ; } else { Log . i ( TAG , "Listener not registered." ) ; } } } ) ; }
Register a listener with the Sensors API.
Register a listener with the Sensors API .
// Optional but recommended for custom data sets. // Can't be omitted.