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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T20:55:26+00:00 2026-06-03T20:55:26+00:00

— This may be a non-issue — I am unable to reproduce this now

  • 0

— This may be a non-issue — I am unable to reproduce this now w/ the device after fixing it and trying to revert back.

So I am a little confused, but here is some code. I changed up the code to simplify it some, so I may have a typo, but this is the ‘gist’ of what I am seeing. But basically on some devices example 1 won’t launch a dialog, while option 2 launches it on all devices:

  1. why the difference in devices/android versions?
  2. should the context not be the same? I know Application Context & View context are different. But not sure why this should work. I know I should not be using getApplicationContext() for a view.. But still a little confused.

(Please note MyTestActivity is a subclass of MyActivity)

Edit: In option #1 the MyActivity gets the Context from a class variable and uses that to launch the dialog.
In option #2 MyTestActivity gets the context (should be same context as MyActivity?) and passes that into the showMessage. (showMessage takes a new parameter in example #2)

Example #1

///////////////////////////////////////////
// THIS Example works on Galaxy Nexus, but not on some other devices, such as : 
// SAMSUNG-SGH-I997. (infuse) - this just simply does not display anything.

public class MyTestActivity extends MyActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.my_layout);
        Intent i = new Intent(MyTestActivity.this, ActivityTwo.class);
        startActivityForResult(i, Constants.FROM_ACTIVITY);
    }

    @Override 
    public void onActivityResult(int requestCode, int resultCode, Intent data) {     
        super.onActivityResult(requestCode, resultCode, data); 
        IntentResult intentResult = IntentIntegrator.parseActivityResult(requestCode, 
                   resultCode, data);
        if ((intentResult != null) && (resultCode == RESULT_OK)) {
             playsound(SOUND_DING); // User hears this - SoundPool
             showMessage("Test Title","Test Message"); // User does not see message
        }
    }
}

public class MyActivity extends Activity {
    private Context mContext;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mContext=this;
    }

    public void showMessage(String title, String message) {
        AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
    builder.setTitle(title);
    builder.setMessage(message)
               .setPositiveButton(mContext.getString(R.string.ok), 
                new DialogInterface.OnClickListener() {
                   public void onClick(DialogInterface dialog, int id) {

                            finish();

                   }
               });
    AlertDialog alert = builder.create();
    alert.show();
    }
}

And example #2

/////////////////////////////////////////////////////////////
// This works on all devices
    public class MyTestActivity extends MyActivity {
        private Context context;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.my_layout);
            context = this;
        Intent i = new Intent(MyTestActivity.this, ActivityTwo.class);
        startActivityForResult(i, Constants.FROM_ACTIVITY);
        }

        @Override 
        public void onActivityResult(int requestCode, int resultCode, Intent data) {     
            super.onActivityResult(requestCode, resultCode, data); 
            IntentResult intentResult = IntentIntegrator.parseActivityResult(requestCode, 
                       resultCode, data);
            if ((intentResult != null) && (resultCode == RESULT_OK)) {
                 playsound(SOUND_DING); // user hears this
                 showMessage("Test Title","Test Message", context); // user sees this
            }
        }
    }

    public class MyActivity extends Activity {
        private Context mContext;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            mContext=this;
        }

        public void showMessage(String title, String message, Context context) {
            AlertDialog.Builder builder = new AlertDialog.Builder(context);
        builder.setTitle(title);
        builder.setMessage(message)
                   .setPositiveButton(context.getString(R.string.ok), 
                    new DialogInterface.OnClickListener() {
                       public void onClick(DialogInterface dialog, int id) {

                                finish();

                       }
                   });
        AlertDialog alert = builder.create();
        alert.show();
        }
    }
  • 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-03T20:55:27+00:00Added an answer on June 3, 2026 at 8:55 pm

    The answer is simple. If you don’t call super.onCreate(savedInstanceState); in your overriden onCreate() you get a garbage instead of context. If you call super.onCreate(savedInstanceState);, you get a working context.

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

Sidebar

Related Questions

I'm currently working on a little harvester, using this dataset of 2700 foundations .
I'm trying to create a chrome extension and im doing this by parsing an
I have set of xml elements like this: <item code=<HTML_CODE> /> For example: <items>
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I am trying to create a modal window for my application, but unfortunately I
&mdash; or &#8212; Is there a difference between these? Is one better-supported than the
I'm using a DatePicker ( org.apache.wicket.extensions.yui.calendar.DatePicker — Javadoc ) in a form. The form
This is a follow-up to the question: Should the folders in a solution match
I'm including a local class that requests a file from a remote server. This
My app uses a WebRequest at certain points to get pages from itself. 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.