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 8847231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:08:55+00:00 2026-06-14T12:08:55+00:00

My app opens a new view from the main view with: Intent ElementsIntent =

  • 0

My app opens a new view from the main view with:

Intent ElementsIntent = new Intent(this, ElementList.class);
startActivityForResult(ElementsIntent, 0);

which shows a list of elements and when pushing 1 of these elements a view opens up the same way as before with a new Activity. Inside this view I would like to show a AlertDialog in a button click handler, but when I call show() the app crashes.

I am pretty sure it has got somthing to do with the Context not being correct according to where I try and open the dialog, but I have tried making a static context from the main view, I have tried with element.this, which is the class connected to the activity, and I have tried getApplicationContext, and all of these result in an app crash.

I hope someone can explain what I am doing wrong.

Thanks.

Here is the AlertDialog code which crashes:

public void GoBackClickHandler(View v)
{
    AlertDialog.Builder builder = new AlertDialog.Builder(ElementItem.this);
    builder.setMessage("Skal ændringer i besvarelse gemmes?")
           .setCancelable(false)
           .setPositiveButton("Ja", new DialogInterface.OnClickListener() {
               public void onClick(DialogInterface dialog, int id) {
                   dialog.cancel();
                if(inputIsValue())
                {
                    UpdateELement task = new UpdateELement();
                    task.applicationContext = ElementItem.this;
                    task.execute(1);
                }
               }
           })
           .setNegativeButton("Nej", new DialogInterface.OnClickListener() {
               public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                    finish();
               }
           });
    AlertDialog alert = builder.create();
    alert.show();       
}

If I move this code to the OnCreate, then the alert shows just fine and no app crash. It is only if I place it in a ClickHandler it crashes.

  • 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-14T12:08:56+00:00Added an answer on June 14, 2026 at 12:08 pm

    I finally found a soloution to this issue.

    I had to save the context of the Activity in a variable in the onCreate method and then use this in the ClickHandler AlertDialog call, then everything works.

    Hope this will be of help to someone else with this annoying problem.

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

Sidebar

Related Questions

I have an app that opens a non-modal form from the main form. The
I use a script which opens the story editor like this: app.menuActions.itemByID(119793).invoke(); How can
I'm trying to start a new activity from a non-activity class. From the main
I have an Activity ( Main ) which shows tabs like this: private void
How do I open SMS from my app and have the new message popped
In my app I have the WebView which shows html files. So I want
In my app i have one use case Download Folder(s) from web server this
I need to get a reference to the main Activity from a Service. This
Im trying to built this app which simple consist of a ListView and different
Right now I have an alarm on my main activity which launches a class

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.