why doesn't the startactivity method work when calling view from presenter?

In the presenter, I access the database and, if the response is successful, start a new activity from the view

Code :

    mRepository.setUrl(resources.getString(R.string.url_server) + resources.getString(R.string.url_authorization));
    mRepository.setJson(getJsonQuery());
    mRepository.setRequest("post");
    mRepository.loadResponse(new ModelDB.CompleteCallback() {
        @Override
        public void onComplete(String response) {
            mView.hideProgressDialog();
            if (response.equals("successful")) {
                //авторизация пройдена успешна, перехожу к карте
                Intent intent = new Intent(mView.getContextView(), MapView.class);
                intent.putExtra("main_user", mView.getUsername());
                intent.putExtra("tittle_user", mView.getUsername());
                mView.startActivity(intent);
            } else {
                mView.showToast(response);
            }

Code from View

@Override
public void startActivity(Intent intent) {
    startActivity(intent);
}

MView and mRepository components of the MVP application.

In runtime, the error

09-26 14:41:11.336 22352-22352/popovvad.findme E/AndroidRuntime: FATAL EXCEPTION: main Process: popovvad.findme, PID: 22352 java.lang.StackOverflowError: stack size 8MB at popovvad.findme.authorization.AuthorizationView.startActivity(AuthorizationView.java:96)

At the same time, the showToast method works for the view, there were no problems with the types. Tell me what I'm doing wrong?

P.S. StackOverflowError

Author: Vadim Popov, 2018-09-26

1 answers

Here, as already pointed out in the comments,

@Override
public void startActivity(Intent intent) {
    startActivity(intent);
}

Your method calls itself, which causes StackOverflowError to occur.

It is better to create a similar method in the view:

Need:

@Override
public void startMapActivity(String mainUser, String titleUser) {
    Intent intent = new Intent(this, MapView.class);
    intent.putExtra("main_user", mainUser);
    intent.putExtra("title_user", titleUser);
    startActivity(intent);
}

And accordingly the call:

mRepository.setUrl(resources.getString(R.string.url_server) + resources.getString(R.string.url_authorization));
mRepository.setJson(getJsonQuery());
mRepository.setRequest("post");
mRepository.loadResponse(new ModelDB.CompleteCallback() {
    @Override
    public void onComplete(String response) {
        mView.hideProgressDialog();
        if (response.equals("successful")) {
            mView.startMapActivity(mView.getUsername(), mView.getUsername());
        } else {
            mView.showToast(response);
        }
    }
}
 2
Author: Nikita Remnev, 2018-09-27 07:52:41