Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8947967
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:53:35+00:00 2026-06-15T12:53:35+00:00

I am attempting to prompt a user for input based on prior input. Allow

  • 0

I am attempting to prompt a user for input based on prior input.

Allow me to clarify and add some context:
This application is a dice-rolling simulator. The main activity displays the number of dice and number of sides on each die, which is changed by opening a sub-activity from the menu. This sub-activity is called for its result using startActivityForResult(), and consists entirely of a RadioGroup and two buttons – “Accept” and “Cancel” – and passes a String extra back to the main activity (in the format “XdN” – e.g. “1d20”), which the main activity then parses and uses to adjust the dice count and side count accordingly.

This system works exceptionally well for examples like “1d6”, “1d10”, and the like, and is not the problem – as far as I know.

Now, here’s my problem:
I have a radio button that passes the String “Custom” (instead of an “XdN”-like String). When selected (and, finally, when “Accept” is clicked), my intention is for a dialog to open and prompt the user for custom count values – and this works, sort of. The dialog shows, and the layout is correct and looks like it should, but the layout then disappears after a split-second and passes the current count values instead of the values that would have been entered by the user. This also throws an error to LogCat (I’m using Eclipse and ADT) that says:

Application            Tag             Text
org.x3chaos.nicedice   WindowManager   Activity org.x3chaos.nicedice.DiceActivity
                                       has leaked window com.android.internal.pol
                                       icy.impl.PhoneWindow$DecorView@44786f20 th
                                       at was originally added here
org.x3chaos.nicedice   WindowManager   android.view.WindowLeaked: Activity org.x3
                                       chaos.nicedice.DiceActivity has leaked win
                                       dow com.android.internal.policy.impl.Phone
                                       Window$DecorView@44786f20 that was origina
                                       ly added here
org.x3chaos.nicedice   WindowManager   at android.view.ViewRoot.<init>(ViewRoot.j
                                       ava:247)

[more if needed]

—

The Button button_accept‘s android:onClick method follows:

public void accept(View view) {

    RadioGroup group = (RadioGroup) findViewById(R.id.dice_radiogrp);
    RadioButton selected = (RadioButton) findViewById(group
            .getCheckedRadioButtonId());
    String tmpResult = selected.getText().toString();

    if (!tmpResult.matches("[0-9|xX](.*)[Dd][0-9](.*)")) {

        // Show dialog

        LayoutInflater li = LayoutInflater.from(this);
        View dialogView = li.inflate(R.layout.prompt_dice, null);

        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setView(dialogView);
        builder.setTitle("Custom Dice");
        builder.setCancelable(false);

        final EditText editCount = (EditText) findViewById(R.id.edit_promptDiceCount);
        final EditText editSides = (EditText) findViewById(R.id.edit_promptDiceSides);

        builder.setPositiveButton("Accept", new OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {

                boolean flag = false;
                String textCount, textSides;
                textCount = editCount.getText().toString();
                if (textCount.equals("")) {
                    textCount = "1";
                    flag = true;
                }
                textSides = editSides.getText().toString();
                if (textSides.equals("")) {
                    textSides = "20";
                    flag = true;
                }

                int count = Integer.parseInt(textCount);
                int sides = Integer.parseInt(textSides);

                if (count > 20)
                    count = 20;
                if (sides > 20)
                    sides = 20;

                String finRes = count + "d" + sides;

                setResultExtra(finRes);

                if (flag) {
                    String msg = "Invalid input: set dice to " + finRes;
                    Toast toast = Toast.makeText(context, msg,
                            Toast.LENGTH_SHORT);
                    toast.show();
                }

            }

        });

        builder.setNegativeButton("Cancel", new OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.cancel();
                exitActivity(false);
            }

        });

        AlertDialog dialog = builder.create();
        dialog.show();

    } else {
        result = tmpResult;
    }

    exitActivity(true);

}

All other functions work, so I’m not sure why this isn’t. I’m sure it’s something that I’m messing up – seeing as this is my first app and I’m using some objects and methods that I’ve never touched before – so I really appreciate any help. :]

EDIT: After reading this question, I’m starting to think that maybe it’s an Intent that’s not waiting for the dialog to finish. But this doesn’t quite make sense, since the activity that calls the dialog is called for a result.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T12:53:36+00:00Added an answer on June 15, 2026 at 12:53 pm

    In Android dialogs are asynchronous. You cannot display it and expect that your code waits here. And what you do is dialog.show() and then instantly exitActivity() so it seems it works the way you made it.

    EDIT

    Quick fix for your code could probably be to replace this portion:

    } else {
        result = tmpResult;
    }
    
    exitActivity(true);
    

    with

    } else {
        result = tmpResult;
        exitActivity(true);
    }
    

    becasue this exitActivity() is what causes you problems.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am validating input on a form and attempting to prompt the user of
I'm having some trouble with a word add-in. I'm attempting to create a new
I am currently attempting to have the browser automatically prompt the user to save
Attempting to use the data series from this example no longer passes the JSONLint
I have a view that, when clicked, should prompt the user to make a
I'm very new to rails and attempting to deploy some changes to my production
I'm trying to add a .NET 4.0 .dll to the GAC. I am attempting
Attempting to follow this Java tutorial . About 63 pages in, you are instructed
I am attempting to make a program that will input numbers into an array
If you don't want any context or an example of why I need this,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.