In the presenter I appeal to the database and in case of a successful response, I start a new activation 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 MVP application components.

Runtime error

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

In this case, the showToast method of the view works, there were no problems with the types. Tell me what I'm doing wrong?

PS StackOverflowError

  • one
    Try to transfer not the content in the view, but the data (main_user and tittle_user), and there you already have to pack in the intent - RomanK.
  • 2
    Well, you have redefined the Activity method so that it always calls itself, so the stack ends. Either call the ancestor method via super , or rename the method in the interface so that you do not have to override it. - zRrr pm

1 answer 1

Here, as already indicated in the comments,

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

Your method calls itself, which causes a StackOverflowError .

It is better to create a similar method in view:

Need to:

 @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 challenge:

 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); } } } 
  • That's exactly what I did, thanks - Vadim Popov