Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting Dialog to display one time
    primarykey
    data
    text
    <p>I have an alert dialog in my application that launches as soon as the application does. I want my <code>alertDialog</code> only to display when the activity is first launched after it has been installed after that I do not want the <code>alertDialog</code> to ever pop up again unless the user deletes the application an d then installs it again. I have tried looking to see how can I achieve this method and tried learning to write the proper code but I just can not seem to get it done properly. So can somebody help me achieve this method and get around this issue.</p> <pre><code> public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); boolean initialDialogDisplayed = preferences.getBoolean("InitialDialog", false); if (!initialDialogDisplayed) { Editor editor = preferences.edit(); editor.putBoolean("InitialDialog", true); editor.commit(); final AlertDialog.Builder alertDialog = new AlertDialog.Builder(this); alertDialog.setTitle("Alert"); alertDialog.setIcon(R.drawable.ic_launcher); alertDialog.setMessage("Dialog"); alertDialog.setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { } }); alertDialog.show(); final EditText et = (EditText) findViewById(R.id.editText1); Button getAnswer = (Button) findViewById(R.id.button1); getAnswer.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (et.getText().toString().length()==0) { Toast.makeText(getApplicationContext(),"Can't Be Blank!",Toast.LENGTH_LONG).show(); }else{ EditText et = (EditText) findViewById(R.id.editText1); String searchTerm = et.getText().toString().trim(); Intent in = new Intent(MainActivity.this, ListView.class); in.putExtra("TAG_SEARCH", searchTerm); startActivity(in); } } }); } } @Override protected void onStop() { // TODO Auto-generated method stub super.onStop(); }} </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload