Reputation: 157
It's possibile to start a dialog from other activity ?
Upvotes: 0
Views: 1607
Reputation: 774
If will add the dialog code in any global class and pass the context as a parameter to display the dialog on each activity,in any activity if its displaying dialog and if ll change the orientation the dialog wont be visible, better to override and use OncreatDialog() for each activity.
Upvotes: 0
Reputation: 12032
No I don't think so, and if it is you shouldn't. Each dialog should be created in the context of the current activity. For what reason do you want to do this?
If your doing it because you want to save code, it makes much more sense to create a new class called something like DialogFactory. Then you can have a static method that takes a context as a parameter and creates a dialog. This way you can just call
Dialog myDialog = DialogFactory.createDialog(this);
any time you need to use that dialog.
Heres an example of what createDialog() could look like
public static Dialog createDialog(Context context){
Dialog dialog = new Dialog(this);
dialog.setContentView(R.layout.your_dialog_view);
//set your title, message, buttons etc.
return dialog;
}
Upvotes: 1