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

  • SEARCH
  • Home
  • 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 8398845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:08:56+00:00 2026-06-09T21:08:56+00:00

I don’t need the code for the creation Dialog box on an activity. I

  • 0

I don’t need the code for the creation Dialog box on an activity.
I use opengles and i am drawing with the renderer class i create . I think the execution at the android activity window stays at main activity.
I have states of my drawing and when a draw reach a state i want to post a dialog box. So there is a problem with that because the dialogbox builder wants a context and the renderer class isnt an activity object.
I am new at opengles and firstly all the work i do exists at
method

public void onDrawFrame(GL10 gl)
{ }

so i have 2 classes 1st the ui class

mainactivity extends activity

and second the renderer class

class mainrenderer implements GLSurfaceView.Renderer

i want from the second class to use activity operations such as create dialog box .
Can you give me a solution to this ?
Thanks.

In other words i want from a class (renderer) that isn’t ui class to make a dialogbox .

edited

i pass the context of my activity class
as myrender = new Renderer1(this);
at constructor of Renderer i have

class Renderer1 implements GLSurfaceView.Renderer
/* initializations */

public Renderer(Context context) {
 super();
 mcontext = context; 
}

and after that i have implement the on drawFrame method and when i reach a state i call the method alertdialogbox()
given below

 public void alertdialogbox()  /* some code */  AlertDialog.Builder
 builder = new AlertDialog.Builder(mcontext);

but it keeps erroring and application crashes when reach the state that the alertdialogbox called

the error begins with

java.lang.RuntimeException : Can’t create handler inside thread that
has not called Looper.prepare()

Edit 2 solved
i initialize a handler at main activity as :

Handler handler = new Handler() {
          @Override
          public void handleMessage(Message msg) {
              alertdialogbox();
             }
         };

alertdialogbox is a method that i declare inside main activity class
and constructs the dialogbox

again inside the main activity where i instantiate the GlsurfaceView and the Glrenderer
i pass the handler that i initialize before so :

    Renderer = new Renderer1(handler);  
after that at the class Renderer1

    class Renderer1 implements GLSurfaceView.Renderer
     Handler mhandler;

    public Renderer( Handler handler) {
     super();
     mhandler = handler; 
    }

    *
    *
public void onDrawFrame(){
*
*

if (state) 
{ 
alertdialogbox();
 }
}
*
*
     public void alertdialogbox()
        {

            mhandler.sendEmptyMessage(1);

        }

and finally i have my dialogbox viewed.

thanks for the suggetions .

  • 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-09T21:08:57+00:00Added an answer on June 9, 2026 at 9:08 pm

    When creating a AlertDialog (or any other UI widget) from another class, you must have a reference to your activity class and with that object, you can call activity.runOnUIThread() to execute any code related to your AlertDialog.

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

Sidebar

Related Questions

Don't ask me why but i can't use this method because I need to
Don't think there's much to say, here's my code for (int i = 0;
don't know better title for this, but here's my code. I have class user
don't know what happened in my jcrop selection. I think I pressed some keys
Don't be scared of the extensive code. The problem is general. I just provided
Don't ask me why but I need to do the following: string ClassName =
I don't know why, but this code worked for me a month ago... maybe
Don't think that I'm mad, I understand how php works! That being said. I
Don't be afraid to use any technical jargon or low-level explanations for things, please.
Don't be frightened, its a very basic code. Just wanted to check with you

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.