Q:

how to call an intent from a different class

I am trying to call an intent from a handler and I don't know how to do it. I have tried many different ways but it does't seem to be working. I want to start the PrimeNumbersActivity when the progress dialog reaches its max.
public class MyHandler extends Handler {
    ProgressDialog progressDialog;
    Context context;

    public MyHandler(ProgressDialog progressDialog) {
        this.progressDialog = progressDialog;
    }

    public MyHandler(Context context){
        this.context = context;
    }

    @Override
    public void handleMessage(Message msg) {
        findPrimeNumber(Integer.parseInt(msg.obj.toString()));
    }

    public void findPrimeNumber(int number){

        ArrayList<Integer> primeNumbers = new ArrayList<>();
        boolean isPrimeNumber;
        PrimeNumbers primeNumbers1 = new PrimeNumbers();

        for(int i = 2; i <= number; i++){
            isPrimeNumber = true;
            for(int j = 1; j <= i; j++){
                try {
                    sleep(50);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                if(j != 1 && j != i){
                    if(i%j == 0){
                        isPrimeNumber = false;
                        break;
                    }
                }
            }
            if(isPrimeNumber){
                primeNumbers.add(i);
                primeNumbers1.primeNumbers.add(i);
            }
            progressDialog.setProgress(i*100/number);
            if(progressDialog.getProgress() == progressDialog.getMax()){
                progressDialog.dismiss();
                Intent intent = new Intent(context.getApplicationContext(),PrimeNumbersActivity.class);
                context.startActivity(intent);
            }
        }

        for (int i :
                primeNumbers) {
            Log.d(TAG, i + "");
        }
    }
}

the PrimeNumbersActivity
public class PrimeNumbersActivity extends AppCompatActivity {

    private PrimeNumbers primeNumbers = new PrimeNumbers();
    private ListView listView;

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

        listView = findViewById(R.id.listView);

        if(primeNumbers.primeNumbers.isEmpty()){
            Toast.makeText(getApplicationContext(),"Pas de nombres premiers",Toast.LENGTH_SHORT).show();
        }else{
            ArrayAdapter<Integer> arrayAdapter = new ArrayAdapter<Integer>(getApplicationContext(),android.R.layout.simple_list_item_1,primeNumbers.primeNumbers);
            listView.setAdapter(arrayAdapter);
        }
    }
}

MainActivity
public class MainActivity extends AppCompatActivity {

    public static final int number = 20;
    public Button button;
    public EditText editText;
    public ProgressDialog progressDialog;
    public AlertDialog.Builder alertDialog;

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

        progressDialog = new ProgressDialog(MainActivity.this);
        progressDialog.setMax(100);
        progressDialog.setMessage("Please wait...");
        progressDialog.setTitle("Finding prime numbers");
        progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);

        final MyThread thread = new MyThread(progressDialog);
        thread.setName("MyThread");
        thread.start();

        button = (Button) findViewById(R.id.afficherNombrePremier);
        editText = (EditText) findViewById(R.id.editText);

        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(editText.getText().toString().isEmpty()){
                    alertDialog = new AlertDialog.Builder(MainActivity.this);
                    alertDialog.setTitle("Warning");
                    alertDialog.setMessage("Veuillez saisir un nombre entier dans la zone de texte");
                    alertDialog.show();
                }
                else{
                    progressDialog.show();
                    Message message = Message.obtain();
                    message.obj = editText.getText().toString();
                    thread.mHandler.sendMessage(message);
                }

            }
        });
    }
}

Error:
04-24 00:45:15.457 4625-4712/com.example.mohammed.tdservicesex1 E/AndroidRuntime: FATAL EXCEPTION: MyThread
                                                                              Process: com.example.mohammed.tdservicesex1, PID: 4625
                                                                              java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Context android.content.Context.getApplicationContext()' on a null object reference
                                                                                  at com.example.mohammed.tdservicesex1.MyHandler.findPrimeNumber(MyHandler.java:65)
                                                                                  at com.example.mohammed.tdservicesex1.MyHandler.handleMessage(MyHandler.java:31)
                                                                                  at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                                  at android.os.Looper.loop(Looper.java:154)
                                                                                  at com.example.mohammed.tdservicesex1.MyThread.run(MyThread.java:22)

Thread:
public class MyThread extends Thread {
    private static final String TAG = MyThread.class.getSimpleName();
    public MyHandler mHandler;
    ProgressDialog progressDialog;

    public MyThread(ProgressDialog progressDialog) {
        this.progressDialog = progressDialog;
    }

    @Override
    public void run() {
        Looper.prepare();
        mHandler = new MyHandler(progressDialog);
        Looper.loop();
    }
}

A:

The error is happened because you haven't set any context with your constructor in your MyHandler class. Your constructors is like the following:
public class MyHandler extends Handler {
  ...

  public MyHandler(ProgressDialog progressDialog) {
    this.progressDialog = progressDialog;
  }

  public MyHandler(Context context){
    this.context = context;
  }

  ...
}

you can see that you have 2 different constructors. In your code, you're only using the first constructor, you never assign the context with your second constructor. This is a common error when you're using multiple constructor for a class. 
To solve the problem, you need to change your constructor so that it needs two parameters: ProgressDialog and Context. Change the constructor to something like this:
public class MyHandler extends Handler {
  ...

  public MyHandler(ProgressDialog progressDialog, Context context) {
    this.progressDialog = progressDialog;
    this.context = context;
  }

  ...
}

