Reputation: 4874
My Android application needs to show a dialog on first use of the application. This application also uses a custom Application class that extends Androids Application class. I want to use a DialogFragment for this dialog (because the documentation states that the showDialog() method is deprecated), and show this DialogFragment in the onCreate() method of my custom Applicaton class. The code to show a DialogFragment is as follows:
FragmentManager manager = getSupportFragmentManager();
DialogFragment firstUseDialog = new FirstUseDialog();
firstUseDialog.show(manager, "dialog");
But the getSupportFragmentManager() method is not available in an Application class, only in Activity classes. So my question is if there is another way to show a dialog from the Application class.
I can always move the first use code into my main activity, but I just wanted to check if it is possible to do in an Activity class. I feel like an applicaton first use check should be part of the Application class and not of an Activity class.
Upvotes: 1
Views: 2431
Reputation: 1006869
But the getSupportFragmentManager() method is not available in an Application class, only in Activity classes.
getSupportFragmentManager()
is not available from Activity
, either. It is available from FragmentActivity
of the Android Support package.
So my question is if there is another way to show a dialog from the Application class.
Not that way.
I feel like an applicaton first use check should be part of the Application class and not of an Activity class.
You are certainly welcome to your opinion. IMHO, displaying the UI is the responsibility of an activity and only an activity. The fact that this happens to only occur on the first use of app does not change that.
Upvotes: 2