In my Activity I have Fragment (ContactBox) which contains "Send" button. If this button`s action fails, user sees error (DialogFragment). I want to implement "Try Again" button on this error, but I dont know how to pass retry action from first Fragment to second DialogFragment. Do you have any ideas? Retry method is placed in ContactBoxFragment.
Related
I have a global empty state fragment that is shown whenever a network request fails to reach API. The fragment shows a simple error message and a "Retry" button.
I can navigate to the fragment from any other fragments of my app so the "parent" fragment is never the same.
I want to find a way to pass a callback to the empty state fragment so that whenever the user clicks on the "retry" button, I can retry the network call that triggered the empty state and check if the call worked in order to navigate back to the previous fragment.
I think that the recommended way should be using viewModel but since the empty state fragment could be call from any other fragment, the view model containing the network call would also, never be the same.
I wanted to know what would be the best approach here.
Thank you.
I am using a AppCompatDialogFragment. My dialogFragment is not dismissed in some scenario.
The scenario flow is
Showing the dialogFragment
dialogFragment UI has a Button.In button click a api is called and after api response i dismiss the dialog and set an myObject to null as i don't need that object.
Then i show second dialog and user manually dismiss this dialog
After dismissing second dialog users are able to interact(click on that button) with first dialogFragment
I am getting a crash on dialogFragment button click for null object reference on myObject which i previously set to null.
User is able to click button after dialogFragment dismiss call. As i have set myObject to null first time so i'm getting Exception.But user shouldn't able to click second time as i have called dismiss().
I can't generate this Exception and its happening in live in some cases and i have traced the scenario with Crash Log
Crash happens only when user are able to click second time
Why the dialogFragment is not dismissing some case? I am using dialogFragment.dismiss() method for dismiss.
Is this happening for state loss issue? But i think for state loss issue i should get a Exception for IllegalStateException
A workaround may be getSupportFragmentManager().executePendingTransactions() .
Any one can explain the scenario ? why this happening or how to solve this.
Thanks in Advance
I have an quiz app. and i want the user to choose the type of questions from alert dialog . so the alert dialog has a check boxes buttons so if the user can select more then on type. when the user click the positive button in alert dialog it will send info to if condition then the condition will filter the questions and then will pass it to an array. the problem is the array its inside oncreate and i want the alert dialog to be in same class so when i run the class oncreate will start and i get null exception because i didn't pass any info to the array.
How can i delay oncreate() and make it load only after the user click on positive button of alert dialog.
The alert dialog will be in same class .
So how can i do it ? is it possible?
and thanks.
onCreate() is the first called when the activity is created per the android activity lifecycle so, no. I'm not sure why you would want it in the same activity if you don't want it to start unless they click 'OK'. Put it in it's own class or the previous activity.
No you cannot, if you attempt to delay something within the OnCreate() method within an activity it will throw an exception as you don't have a context to place the alert dialog in at that time. As codeMagic previously stated, if you have a prior activity before this one, your best bet would be to create the alert prior to calling startActivity on that intent.
I would suggest to use Fragments in this case. Load Activty, show dialog and based on the answer you will display "correct answer fragment" or "invalid answer fragment".
With this solution activity is loaded (no need to delay) and you just dynamically change the content of the activity.
Try using the AsyncTask class. The onPostExecute method may do the job you're looking for ..
I have a fragment that has a button.
When I click on button the system opens a dialog fragment where the user can choose some info.
In the dialog there is a button "Ok". When the user clicks on ok, the dialog dismisses and we return on the other fragment.
I want to return to the other fragment with the result(the info choosen).
How can I do it?
There are several way to achieve this:
You can save the result from the Dialog in the activity (getActivity()) and get in from the other Fragment
You can let the base Fragment implement a callback interface and call its callback function when pressing OK from the Dialog. You'll need to pass the interface (probably it'll be "this") as an argument when creating the Dialog Fragment.
Hope this helps.
Friends i have an application with an Activitiy which brings some data from Content Providers and Display it in the textViews and edittext onto the Screen. but before that it prompts me for the username and password in a dialog. i have done all the getting content Providers Stuff in the positiveButton onClick Listener of the Alert Dialog.
It works fine but problem is that if i dont enter username and just press bakc key button it closses down the Dialog Box and the Back Screen is showed without loading the content providers.
Note: I have put my code of alert dialog in the onCreate Function of that activity.
So can u guide me how should i do it that when i press back key on dialog box it also should not display my activity.
Please Help!
your dialog name here.setCancelable(false);
this is working
I would honestly just do:
mDialog.setCancelable(false); //assuming the field mDialog is your Dialog
Then make sure you have both an Okay and Cancel (Positive and Negative) buttons on your Dialog. This way, the back press will do nothing, and you can use the Cancel button to finish your activity as well if desired.
The Dialog interface provides a setCancelable() method which enables precisely this. You call that with a false value and the user won't be able to press the back button to go back to your activity.
You can use method of each activity is : onBackPressed()
http://developer.android.com/reference/android/app/Activity.html
-This is the method which you can override sub method to execute when user enter back key.