Q:

Dismiss android activity displayed as Popup

So i have a service, that starts an activity displayed as a Popup thank's to "android:style/Theme.Dialog"
This Activity shows a Listview, with a list of application.
On each element of the listview, there is a short description of the application, and two buttons.
1 for launching the application
2 for displaying a toast with more informations.
Here is the code in my service : it starts the activity
Intent intent = new Intent(this, PopUpActivity.class);
intent.addFlags(Intent.FLAG_DEBUG_LOG_RESOLUTION);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getApplicationContext().startActivity(intent);  

this activity uses a custom layout, with a listview, adapted with a custom ArrayAdapter
In this adaptater, i've put an action on the start button in order to start the current application 
Button lanceur = (Button) v.findViewById(R.id.Buttonlancer);
            lanceur.setOnClickListener(new View.OnClickListener() {

                public void onClick(View v) {
                    p.start(mcontext);
                }
            });

with p.start, i start the application.
But now, if i press "back" from the application, i go back to the popup... and i can start another application. I don't want it to be possible.
That's why i wish i could dismiss/destroy/finish my PopupActivity, but i can't manage to do it with the code i have.

A:

This can be done with startActivityForResult() and  onActivityResult()
 Intent intent = new Intent(this, PopUpActivity.class);
 intent.addFlags(Intent.FLAG_DEBUG_LOG_RESOLUTION);
 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
 getApplicationContext().startActivityForResult(intent,1); 

 @Override
 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
     Log.d("CheckStartActivity","onActivityResult and resultCode = "+resultCode);
     // TODO Auto-generated method stub
     super.onActivityResult(requestCode, resultCode, data);
     this.finish();
 }

and add in AndroidManifest.xml:
<activity android:name=".PopUpActivity" android:noHistory="true" />

