Android how to execute two dialogs in a certain order - android

I have coded two dialogs in Android, which individually works.
But the first dialog is rapidly replaced by the second dialog without permetting an answer.
My question is : how to force an order of execution (my code can wait for an answer on the first dialog).
My solution could be to exchange dialogs execution order to be sure that the second dialog is the first launched.
But I wonder if the is a better solution ?
I have seen a lot of Android examples on the site, but not really answering my question.

There are two solutions.
First use dialogFragment with Navigation, and upon input from dialog 1, navigate to dialog 2. That is how your first dialog will not be overriden by dialog 2.
Second you can use call back in dialog1, which will be invoked on the input in dialog1, and in your fragment, get that call back and show second dialog.

Related

How? Create AlertDialog inside AsyncTask and then use the result to continue the task

So here is what I'm supposed to do, first, when user press a button, an AlertDialog will pop up and ask the user to enter something, then I get the String from the user and go ahead to search for it on the internet, which should be done in an AsyncTask. So far so good, I don't have any problems with that. But the part that confuses me is that, there might be multiple results, and I need to pop up a new AlertDialog that displays all the results I found and then ask the user to choose one specific result. I know this should be done on the MainThread, still, I don't have a problem, but the problem is, how do I get the thing that the user chose, and use it to continue my AsyncTask?
Thank you!
I think what you need is
AutoCompleteTexView in a Alert dialog and add a TextWatcher.
Call the Asynctask whenever the text changes in TextWatcher and update the adapter of AutoCompleteTexView.
Good thing is AutoCompleteTexView comes with inbuilt suggestion list and onItemClickListener. So that you can the pick the user clicked item.
If your search result is more than a string, then you may have to use the custom adapter and custom filter.
Hope this helps.

solo.clickInlist(int) not working for custom listview in Robotium

I'm new to Robotium, I have two questions.
1) I'm trying to make click on custom listview item but its not working. I tried with clickInList(int) and clickInlist(int, int).
2) Handling random AlertDialog:
How to handle display alert dialog dynamically in Robotium? For example I'm using alert dialog when I get any message during call webservice, like connection failure, no internet, server error, timeout, etc..,
Thanks in advance.
There are two important things to note about the clickInList(int) method that aren't readily apparent: First, the list items are 1-indexed, so to click the first item of the list, use clickInList(1) not clickInList(0). Second, the clicking is relative to the visible items on the screen, so clickInList(1) will click the first visible item on the list, not the first item overall.
As for the dynamic handling of a Dialog, arbitrary pop-ups aren't really what Robotium was meant to handle. It's supposed to test user interaction with the app under known, controlled, repeatable conditions. If something unexpected happens in the middle of the test, such as losing connection, it should be considered a failure; There's a good chance your test wouldn't be able to run to completion anyway. As a hacky work-around, you can check for the existence of the Dialog before each of your events, something like:
if(solo.searchText("Dialog text") {
//handle closing dialog
}
However, I'd advise against this, it'll slow down your test considerably, and again, even if you close the dialog, the fact that the error happened in the first place is probably going to cause a later part of your test to fail.

Sequentially show multiple dialogs?

I'm new to Android and I'm programing an application with multiple user interfaces(windows).
I find it a little hard to define new activity for each window so I end up with using Dialogs more than activity. But there is a scenario where I need to sequentially show multiple dialogs.
In c# showing Dialog is blocking operation. But I don't know how to do that in Android.
if there, I welcome any alternatives.
If you want to show a sequence of dialog, you can use the onclick listeners. From one dialog, open the following one. ( dialog interface for the listeners)
and if you want to block your program, so the user has to click on the dialog, set the dialogs not cancelable (setCancelable)
OK with no code reference I would say the easiest way would be using ondimiss listeners in each dialog for the next one to be called. You can check out this short example to get an idea of implementation (note they are using ondismiss for something else).
http://android-er.blogspot.com/2011/11/cancel-progressdialog.html

Android: The AlertDialog is invisible when the Activity back to foreground

This question is related to The AlertDialog is invisible when the Activity back to foreground post.
I have the same problem. The previous post is old, and have no answer. Any suggestions how to solve that problem ? Thanks...
For some reason, Dialogs' states must be handled by the developer.
Simply keep a reference to the dialog showing
For example
Dialog showingDialog=null;
Now in onResume()
if(showingdialog!=null)
//show the dialog and maybe resume some state
Have you tried to re-display the AlertDialog when in the activities onResume(). Using Google developers example you would be able to create an instance of this dialog and just recall it.
http://developer.android.com/guide/topics/ui/dialogs.html#AlertDialog
Hope that helps.
Also we all create Dialogs on the fly whenever we need them, we should not.
Android way is (by the book) to override an onCreateDialog(int) and showDialog(int) in our activities so that our dialogs can be managed by the activity lifecycle.
Another way to do so is to use myDialog.setOwnerActivity(MyActivity.this) to tell the dialog it is managed by the activity.

Android: When to use Dialog vs. Activity

When is it preferable to use a Dialog box as opposed to an Activity in Android? From my understanding, anything you can do with a Dialog box you can also accomplish with an Activity. Are there any tasks that can only be accomplished by an Activity or a Dialog?
Is what you're doing worth a new Activity? Do you need to be able to start it through an intent? Do you really need to create a new Java class for it?
If it's a straightforward dialog that displays a text and has simple hooks for positive/negative/dismissal functions, definitely use a dialog.
If you have something complex, you may want to go for a full-blown activity.
Well why exactly would you want to start a new activity just to ask the user "Are you sure? Y/N"? Dialogs generally run on top of the activity, and are usually smaller activities or notifications for the user. They also usually have something to do with the process of the app running. It helps make things simpler to open a dialog to prompt the user on top of your activity, than to start a new activity atop your current activity.
I went for Activities when I needed an user interaction that needs backstack, navigation, lifecycle and callable features.. else with dialogs. Being from the WebApp world I ask whether I would have needed a new server page or a pop window for an interaction and the decision in Andoird world becomes easier!
If newServer page then mostly Activity
elseIf popUpWindow then dialog
I created my android application in one fragment with nested alert dialog, so far my application still running well in handle those nested dialog, and I think dialog is less consuming memory than an activity

Categories

Resources