These days I'm working on simulating a modal dialog in Android. I have a lot of Google, a lot of discussion, but, unfortunately, there are not many options to get this modal. Here is the background
Dialogs, modal dialogs and locking
Dialogs / AlertDialogs: How to perform "personnel execution" and a dialog up (.NET style)
There is no direct way to get modal behavior, then I came up with 3 possible solutions,
1. Use a dialog action, for example, this thread , but I still cannot get the main activity to wait for the dialog to return. The main activity turned to stop status and was restarted again.
2. Create one workflow and use thread synchronization. However, this is a huge refactoring job for my application, now I have one main action and service as in the main user interface thread.
3. Take event handling in a loop when there is a modal dialog, and end the loop when the dialog closes. This is actually a way of creating a real modal dialogue, like what it does on Windows. I still haven't prototyped this way.
Anyway, I would like to imitate it using dialogue work,
1. Launch the activity dialog using startActivityForResult ()
2. get the result from onActivityResult ()
Here is some source
public class MainActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); MyView v = new MyView(this); setContentView(v); } private final int RESULT_CODE_ALERT = 1; private boolean mAlertResult = false; public boolean startAlertDialog() { Intent it = new Intent(this, DialogActivity.class); it.putExtra("AlertInfo", "This is an alert"); startActivityForResult(it, RESULT_CODE_ALERT);
The calling startAlertDialog blocks execution and waits for the returned result. But startAlertDialog returned right away, of course, and the main action went into STOP, while DialogActivity got up.
So, the question is how to make the main type of activity wait for the result?
Thank.
android synchronization android-activity modal-dialog
fifth May 25 '11 at 6:47 am 2011-05-25 06:47
source share