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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T19:08:39+00:00 2026-05-21T19:08:39+00:00

I am creating a dialog using the getApplicationContext() function and this causes the program

  • 0

I am creating a dialog using the getApplicationContext() function and this causes the program to crash when I call dialog.show(). I am using getApplicationContext() because I am trying to make the dialog open within a Camera.PictureCallback() like this:

Camera.PictureCallback pictureCallbackJpeg = new Camera.PictureCallback()
{
    public void onPictureTaken(byte[] data, Camera c)
    {
        Context context = getApplicationContext();
        Dialog dialog = new Dialog(context);
        dialog.setContentView(R.layout.send_dialog);
        dialog.setTitle("Send image?");
        dialog.show();

        camera.startPreview();
    }
};

Here is the crash log:

Thread [<1> main] (Suspended (exception WindowManager$BadTokenException))   
Dialog.show() line: 245 
myApp$1.onPictureTaken(byte[], Camera) line: 31 
Camera$EventHandler.handleMessage(Message) line: 328    
Camera$EventHandler(Handler).dispatchMessage(Message) line: 99  
Looper.loop() line: 143 
ActivityThread.main(String[]) line: 4914    
Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]  
Method.invoke(Object, Object...) line: 521  
ZygoteInit$MethodAndArgsCaller.run() line: 868  
ZygoteInit.main(String[]) line: 626 
NativeStart.main(String[]) line: not available [native method]  

Any ideas how to fix this?

  • 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-05-21T19:08:40+00:00Added an answer on May 21, 2026 at 7:08 pm

    If you are inside an activity (say MyActivity), you can create the Dialog:

    Dialog dialog = new Dialog(this);
    

    or if you are inside an inner class of an Activity:

    Dialog dialog = new Dialog(MyActivity.this);
    

    Otherwise you could try the getBaseContext().
    You just make sure, that you’re working in the UI thread.

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

Sidebar

Related Questions

I am using javascript to open save dialog box the java script is function
Anyone have any experience creating a modal dialog box using AJAX and ASP.NET MVC?
While creating a file synchronization program in C# I tried to make a method
I'm creating an options dialog using WPF that lists possible keys so that the
I am creating an options dialog using JOptionPane.showOptionDialog(...) ; For the options parameter I
I am creating an options dialog using JOptionPane.showOptionDialog(...) When I click one of the
I am trying to create a wizard like structure using dialog boxes...So I replaced
I'm creating a customer survey using a jQuery UI dialog. I'm loading an external
I'm creating an Alert dialog by using the following: AlertDialog.Builder builder = new AlertDialog.Builder(context);
I'm actually using JQueryUI Dialog plugin to show some information to the users of

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.