I want to create an Extend Dialog class where there is an exit function from the application that is called through the Dialog class itself without going through the Activity class. For example class:
class Example extends Dialog {
private OnDismissListener dismissListener;
public boolean isForceExists;
public void setDismissListener(OnDismissListener listener) {
this.dismissListener = listener;
}
@Override
public void dismiss() {
if (dismissListener != null) {
dismissListener.onDismiss(this);
}
// I want to run this after event OnDismissListener and callback function from Activity.
if (isForceExists != false) {
int id = android.os.Process.myPid();
android.os.Process.killProcess(id);
}
super.dismiss();
}
}
For example action called and quest :
I want to hold AlertDialog first, or handling this event. And callback to dismiss of method's
class Example extends Dialog
public class ExampleActivity extends Activity implements DialogInterface.OnDismissListener {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Example exDialog = new Example(this);
exDialog.isForceExists = true; // --> I want to run this from Example class without this Activity.
exDialog.setDismissListener(this);
exDialog.show();
}
@Override
public void onDismiss(DialogInterface dialog) {
// --> I want to hold AlertDialog first, or handling this event.
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Exit Application")
.setMessage("Thank you for using this application, happy nice day ^_^")
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface subDialog, int which) {
// --> And After show AlertDialog, back event to dismiss
// method of Example extends Dialog again.
Example dialog = new Example(this);
dialog.dismiss();
}
}).show();
// without method -> "finish();", but calling again to Example extends Dialog class.
}
}
Trouble : AlertDialog showing, but immediately exit the application or not handled or skip it!
What is expected for my problem is showing AlertDialog, before dismiss. And then return back to void dismiss from class Example extends Dialog and exit application without from Activity class, but exit or finish from method's class Example extends Dialog.