lunes, 6 de enero de 2020

Do Something on First App Start Only - Android Studio Tutorial

Do Something on First App Start Only


public class MainMenu extends Activity {
  


    @Override    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_basic_views);

        SharedPreferences prefs  = getSharedPreferences("prefs", MODE_PRIVATE);
        boolean firstStart = prefs.getBoolean("firstStart", true);

        if(firstStart)
        { showStartDialog();}

    }

    public void showStartDialog()
    {
        android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(v.getContext());
        builder.setMessage("Check more apps!!!")
                .setCancelable(false)
                .setPositiveButton("OK GO", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                        startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/developer?id=Demilion") ) );
                    }
                })
                .setNegativeButton("NO", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                });
        builder.create()
                .show();

        SharedPreferences prefs = getSharedPreferences("prefs", MODE_PRIVATE);
        SharedPreferences.Editor editor = prefs.edit();
        editor.putBoolean("fistStart", false);
        editor.apply();
    }





https://www.youtube.com/watch?v=2I1n6A6JJzw

No hay comentarios:

Publicar un comentario