#connecting my stepCount activity to my back4app database to store step count, data and user

1 messages · Page 1 of 1 (latest)

lost hill
#

public class StepsActivity extends AppCompatActivity implements SensorEventListener {

private SensorManager sensorManager;
private TextView textView;
boolean running = false;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_steps);

    textView = findViewById(R.id.textView);
    sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
}

@Override
protected void onResume() {
    super.onResume();
    running = true;
    Sensor countSensor = sensorManager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER);
    if (countSensor != null) {
        sensorManager.registerListener(this, countSensor, SensorManager.SENSOR_DELAY_UI);
    } else {
        Toast.makeText(this, "Sensor not found", Toast.LENGTH_SHORT).show();
    }
}

@Override
protected void onPause() {
    super.onPause();
    running = false;
    sensorManager.unregisterListener(this);
}

@Override
public void onSensorChanged(SensorEvent event) {
    if (running) {
        //textView.setText(String.valueOf(event.values[0]));
        Calendar calendar = Calendar.getInstance();
        int currentHour = calendar.get(Calendar.HOUR_OF_DAY);
        int currentMinute = calendar.get(Calendar.MINUTE);
        int currentSecond = calendar.get(Calendar.SECOND);
        if (currentHour == 00 && currentMinute >= 01 && currentSecond >= 0) {
            // Reset step count to 0
            textView.setText("0");
        } else {
            // Update step count
            textView.setText(String.valueOf(event.values[0]));
        }
      }
    }

@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {

}

}

vivid wyvernBOT
#

<@&987246623988019200> please have a look, thanks.

vivid wyvernBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.

Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.