Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Want to display a dialog only once after the app been installed

Tags:

android

How can I make my dialog appear only once after my Android app is installed on the device?

like image 476
joula Avatar asked May 04 '11 05:05

joula


People also ask

How do I get Android to only show one pop up?

yes, new DialogInterface. OnClickListener() { public void onClick(DialogInterface dialog, int which) { // continue with delete Intent intent = new Intent(MainActivity. this, WebActivity. class); startActivity(intent); } }) .

How to show fragment in dialog?

Overriding onCreateView() will let you show a Fragment as dialog and you can make the Title text customized. On the other hand, overriding onCreateDialog(), you can again show a fragment as dialog and here you can customize the entire dialog fragment. Means, you can inflate any view to show as dialog.

How to show dialog in android studio?

setTitle(CharSequence title)AlertDialog alertDialog = alertDialogBuilder. create(); alertDialog. show(); This will create the alert dialog and will show it on the screen.


1 Answers

Use SharedPreference to store the firstrun value, and check in your launching activity against that value. If the value is set, then no need to display the dialog. If else, display the dialog and save the firstrun flag in SharedPreference.

ex (in your launching activity):

public void onCreate(){
    boolean firstrun = getSharedPreferences("PREFERENCE", MODE_PRIVATE).getBoolean("firstrun", true);
    if (firstrun){
        //... Display the dialog message here ...
        // Save the state
        getSharedPreferences("PREFERENCE", MODE_PRIVATE)
            .edit()
            .putBoolean("firstrun", false)
            .commit();
    }
}
like image 182
xandy Avatar answered Nov 15 '22 09:11

xandy