Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Returning from a dialog or activity with result

Tags:

I would like to know if I can freeze the current Activity, while I wait for another activity or dialog (any would do) to finish.

I know I can start an activity for results, and handle those there, but the code after startActivityForResult() will still get executed

this is something I would like to do:

PopupDialog dialog = new PopupDialog(this,android.R.style.Theme_Black_NoTitleBar); dialog.show(); // wait here, and continue the code after the dialog has finishes int result = getResultFromDialogSomehow(); if (result == 1){     //do something }else{     //do something else } 

I know this must sound quite weird, but but I would really appreciate it if anyone can tell me how to achieve such functionality.

like image 539
zidarsk8 Avatar asked Jul 29 '11 03:07

zidarsk8


1 Answers

You can use onActivityResult also
In your main activity call
startActivityForResult(intent, 1); //here 1 is the request code

In your Dialog class

Intent intent = new Intent(); intent.putExtra(....) //add data if you need to pass something setResult(2,intent); //Here 2 result code 

so your main activity

@Override protected void onActivityResult(int requestCode, int resultCode, Intent data){ if (resultCode == 2 && requestCode ==1){     //do something }else{     //do something else } } 
like image 154
Labeeb Panampullan Avatar answered Oct 16 '22 05:10

Labeeb Panampullan