PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, July 12, 2022

[FIXED] How to show a message box before star an activity?

 July 12, 2022     alert, android, android-activity, dialog, message     No comments   

Issue

In my activity i throw a new one with this code:

    intent = new Intent(this, NewActivity.class);
    startActivity(intent);

How to show a message before launching new activity? I would like to show a warning to users before going to new activity, in which just press OK button to go on...


Solution

Simply create a dialog.

Dialog dialog = new AlertDialog.Builder(getActivity())
               .setMessage(R.string.dialog_fire_missiles)
               .setPositiveButton(R.string.fire, new DialogInterface.OnClickListener() {
                   public void onClick(DialogInterface dialog, int id) {
                       Intent intent = new Intent(MainActivity.this, NewActivity.class);
                       startActivity(intent);
                   }
               })
               .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                   public void onClick(DialogInterface dialog, int id) {
                       // User cancelled the dialog
                   }
               }).create();

dialog.show();


Answered By - Misagh Emamverdi
Answer Checked By - Terry (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing