android - Making Retrofit request from DialogFragment -


I have implemented a login Daylogfragment in your app (API 1 9). I am using retrofit 1.7.1 for networking. Implementation is below:

  public class SignInDialogFragment extends DialogFragment {private EditText mUsernameEditText; Private editing text MPasswordEditText; Public Static SignInDialogFragment newInstance () {New SignInDialogFragment ()); } @ Override saved public dialogue on Crete Dialig (bundled Instansstet) {final Builder = new Alrtdaylog Kbilder (GetActivity ()) Kset Positivbtn (r. String.akshn_signi_in new dialog interface Konkliklaistr () {@ Override public Whoid onclick (DialogInterface dialog, int which) {string username = mUsernameEditText.getText (.) toString () ;. APIFactory.getAPI () register (username, new callback & LT; RegistrationResponseModel & gt; () {@Override public void Saf Lata (RegistrationResponseModel registrationResponse, response) {Toast.makeText (getActivity (), "! Has worked perfectly", Toast.LENGTH_SHORT) .show ();} @Override public void failure (RetrofitError error) {Toast.makeTe Xt (getActivity (), "Some Fail!", Toast .LENGTH_SHORT) Show ();}});}}). SetNegativeButton (R.string.action_cancel, null); See View = getActivity () GetLayoutInflater (). Flow (R. Late Fragment_sign_in, blank); Builder.setView (see); MUsernameEditText = (EditText) view.findViewById (R.id.usernameEditText); Return builder.cent (); }}  

As you can predict, it is getActivity () hit a clear reference to crashing on the success or failure What is the Good way is an asynchronous request like this, the dialogue has been rejected after getting the callback done with

Did I think of a few options? Any of them viable?

If there is a request in progress then I can just open the dialogue. I have not implemented this because I'm not sure about the obvious way to keep dialogue (dealing with back buttons, etc.)

Because if I really want to cancel the request is closed, but I can not, because the reason is.

If there is an option that I am not aware of, I want to hear about it.

You should take your action out of the dialog. Dialog activity is not there - Once the user had liked one, the dialog should be dismissed and if there is any action to trigger it, then it will be feedback for the user action with the dialog Should be done in, but it should not be part of the dialogue. So you should only react to the user's choice in your favorite fragment or activity, not in dialog.


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -