this is my code to recognize user activity based on gyroscope and accelerometer firstly if you see any way to improve you are welcome to modifier my code the second thing is I want adding a jumping activity but i don’t know the thresholds 
import androidx.appcompat.app.AppCompatActivity;

import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;

import android.widget.Toast;

import androidx.core.app.NotificationCompat;

import org.project.ayoub_akanoun_projet.databinding.ActivityRecogniweWsensorBinding;
import org.project.ayoub_akanoun_projet.db.DatabaseHelper;
import org.project.ayoub_akanoun_projet.entities.Activity;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class RecogniweWSensorActivity extends AppCompatActivity implements SensorEventListener {


    ActivityRecogniweWsensorBinding binding;
    private SensorManager sensorManager;
    private Sensor accelerometerSensor, gyroscopeSensor;
    private List<Float> accelerometerValues;
    private List<Float> gyroscopeValues;
    String email;
    DatabaseHelper db;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        binding = ActivityRecogniweWsensorBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        email = getIntent().getStringExtra("email");

        // Initialize sensor manager and sensors
        sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
        accelerometerSensor = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
        gyroscopeSensor = sensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
        accelerometerValues = new ArrayList<>();
        gyroscopeValues = new ArrayList<>();
        db = new DatabaseHelper(this);

    }

    @Override
    protected void onResume() {
        super.onResume();
        // Register sensor listeners
        sensorManager.registerListener(this, accelerometerSensor, SensorManager.SENSOR_DELAY_NORMAL);
        sensorManager.registerListener(this, gyroscopeSensor, SensorManager.SENSOR_DELAY_NORMAL);
    }

    @Override
    protected void onPause() {
        super.onPause();
        // Unregister sensor listeners to save battery
        sensorManager.unregisterListener(this);
    }

    @Override
    public void onSensorChanged(SensorEvent event) {
        /* The accelerometer measures the acceleration of the device in three axes (x, y, and z)
         and adds the result to the list accelerometerValues */
        if (event.sensor == accelerometerSensor) {
            float x = event.values[0];
            float y = event.values[1];
            float z = event.values[2];

            float acceleration = (float) Math.sqrt(x * x + y * y + z * z);

            accelerometerValues.add(acceleration);

        /* The gyroscope measures the rotation of the device in three axes (x, y, and z)
         and adds the result to the list gyroscopeValues */
        } else if (event.sensor == gyroscopeSensor) {
            float x = event.values[0];
            float y = event.values[1];
            float z = event.values[2];

            float rotation = (float) Math.sqrt(x * x + y * y + z * z);

            gyroscopeValues.add(rotation);
        }

        // Update activity based on the average of the sensors values
        updateActivity(getAverageAcceleration(), getAverageRotation());
    }

    //
    private float getAverageAcceleration() {
        float sumAccelerations = 0;
        for (float acceleration : accelerometerValues) {
            sumAccelerations += acceleration;
        }
        return accelerometerValues.isEmpty() ? 0 : sumAccelerations / accelerometerValues.size();
    }

    private float getAverageRotation() {
        float sumRotations = 0;
        for (float rotation : gyroscopeValues) {
            sumRotations += rotation;
        }
        return gyroscopeValues.isEmpty() ? 0 : sumRotations / gyroscopeValues.size();
    }

    private long lastCleaningTime = 0;


    /* compares values to predefined thresholds for each activity.
     * If the average acceleration and rotation values are above the thresholds for a certain activity,
     * that activity is recognized
     * store the activity in the database
     * then notify the user */
    private void updateActivity(float averageAcceleration, float averageRotation) {
        String activityText;
        int icon = R.drawable.sitting;
        // Clean sensor values every 20 seconds
        long currentTime = System.currentTimeMillis();
        if (currentTime - lastCleaningTime >= 5000) {
            Toast.makeText(getApplicationContext(), "Update", Toast.LENGTH_SHORT).show();
            accelerometerValues.clear();
            gyroscopeValues.clear();
            lastCleaningTime = currentTime;
        }

        if (averageAcceleration > 15 && averageRotation > 5) {
            activityText = "Running";
            icon = R.drawable.activity_running;
        } else if (averageAcceleration > 10 && averageRotation > 2) {
            activityText = "Walking";
            icon = R.drawable.activity_walking;
        } else if (averageAcceleration > 5 && averageRotation > 1) {
            activityText = "Standing";
            icon = R.drawable.activity_still;
        } else {
            activityText = "Sitting";
            icon = R.drawable.sitting;
        }

        if(!binding.tvStill.getText().toString().equals(activityText)) {
            Activity activity =  db.getLastActivity();
            if(activity.getEndDate().equals("")){
                db.updateEndDate(new Date().toString(),activity.getId());
            }
            binding.tvStill.setText(activityText);
            binding.imgActivity.setImageResource(icon);
            db.addActivity(new Activity(email, activityText, new Date().toString(),""));
            makeNotification(activityText);
        }
    }


    public  void makeNotification(String accActivity) {
        String channelid = "CHANNEL_ID_NOTIFICATION";
        NotificationCompat.Builder builder =
                new NotificationCompat.Builder(getApplicationContext(), channelid)
                        .setSmallIcon(R.drawable.runner)
                        .setContentTitle("Activity changed")
                        .setContentText("Your are " + accActivity)
                        .setAutoCancel(true)
                        .setPriority(NotificationCompat.PRIORITY_DEFAULT);
        Intent intent = new Intent(getApplicationContext(), RecogniweWSensorActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

        PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, PendingIntent.FLAG_MUTABLE);
        builder.setContentIntent(pendingIntent);
        NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
        if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O){
            NotificationChannel notificationChannel=
                    notificationManager.getNotificationChannel(channelid);
            if(notificationChannel==null){
                int importance = NotificationManager.IMPORTANCE_HIGH;
                notificationChannel = new NotificationChannel(channelid, "NOTIFICATION_CHANNEL_NAME", importance);
                notificationChannel.setLightColor(Color.GREEN);
                notificationChannel.enableVibration(true);
                notificationManager.createNotificationChannel(notificationChannel);
            }
        }
        notificationManager.notify(0,builder.build());
    }

    @Override
    public void onAccuracyChanged(Sensor sensor, int accuracy) {
        // Do nothing
    }


}