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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:52:59+00:00 2026-06-13T02:52:59+00:00

I use an Alert class where I define all alert dialogs to show status

  • 0

I use an Alert class where I define all alert dialogs to show status message to the user.
This because is more comfortable to manage.

A typical dialog defined in this class is

public static void DataCleared(Context con) {
    AlertDialog.Builder builder = new AlertDialog.Builder(con);
    builder.setTitle(R.string.data_cleared_title);
    builder.setIcon(android.R.drawable.ic_dialog_info);
    DialogListner listner = new DialogListner();
    builder.setMessage(R.string.data_cleared_text);
    builder.setPositiveButton("ok", listner);

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

This dialog has an ok button that when is clicked close the dialog.

I show these dialog in whatever activity simply calling

Alerts.DataCleared(MyActivity.this)

Now, in the same way I want to create a dialog with two buttons a Cancel button to close the dialog and a Market button to open a link to another Google Play App

I have tried

public static void TryThisApp(Context con) {
    AlertDialog.Builder builder = new AlertDialog.Builder(con);
    builder.setTitle(R.string.my_title);
    builder.setIcon(android.R.drawable.ic_dialog_info);
    builder.setMessage(R.string.my_text)
       .setCancelable(false)
       .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
           public void onClick(DialogInterface dialog, int id) {
               Intent marketIntent = new Intent(
                        Intent.ACTION_VIEW,
                        Uri.parse("market://details?id=com.myapp.sample"
                                + getPackageName()));
                startActivity(marketIntent);
           }
       })
       .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
           public void onClick(DialogInterface dialog, int id) {
                dialog.cancel();
           }
       });
    AlertDialog diag = builder.create();
    diag.show();
}

But doesn’t work, get various compilation error “Cannot make a static reference to the non static method…”

getPackageName() and startActivity(marketIntent); are underlined red by Eclipse, with this message

How could I fix this issue?
How could I create a dialog with open link and cancel button?

  • 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-13T02:53:00+00:00Added an answer on June 13, 2026 at 2:53 am

    1) You have to invoke getPackageName() and startActivity() on a Context because are instance methods,

    2) If you want to do this from another class have to declare Context con as final since security policies doesn’t allow to refer a non final variable inside an inner class defined in a different method.

    3) (isn’t obligated) you should invert the buttons, usually Cancel is on the left and Confirm on the right

    This is the right code:

    public static void TryThisApp(final Context con) {
        AlertDialog.Builder builder = new AlertDialog.Builder(con);
        builder.setTitle(R.string.my_title);
        builder.setIcon(android.R.drawable.ic_dialog_info);
        builder.setMessage(R.string.my_text)
           .setCancelable(false)
           .setPositiveButton("Cancel", new DialogInterface.OnClickListener() {
               public void onClick(DialogInterface dialog, int id) {
     dialog.cancel();
    
               }
           })
           .setNegativeButton("Market", new DialogInterface.OnClickListener() {
               public void onClick(DialogInterface dialog, int id) {
                   Intent marketIntent = new Intent(
                            Intent.ACTION_VIEW,
                            Uri.parse("market://details?id=com.myapp.sample"
                                    + con.getPackageName()));
                    con.startActivity(marketIntent);
               }
           });
        AlertDialog diag = builder.create();
        diag.show();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Typically if we just use alert(object); it will show as [object Object] . How
Mobile browsers. Jquery dialog alert box. I don't want to use alert() because it
Typical jQuery over-use: $('button').click(function() { alert('Button clicked: ' + $(this).attr('id')); }); Which can be
I use an externel javascript file and i have this, function getdropdownvalue() { alert($(#<%=DLState.ClientID%>));
sometimes i use debug code to alert something in javascript (for example, matching something
i use default demo with 2 links, and alert, now i included hash and
I can use the jquery .data attribute and an alert confirms that it worked,
the javascript:alert code that is being dynamically created ONLY works if I use the
I use an uiwebview into my iphone app. When i display a javascript alert
I use the following javascript function, function get_check_value(formId,checkboxId,TxtboxId) { alert(formId); var c_value = ;

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.