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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T11:51:57+00:00 2026-05-15T11:51:57+00:00

I’m sharing some variables accross activities by using a class like this : public

  • 0

I’m sharing some variables accross activities by using a class like this :

public class Globals {

static Boolean hint1_graph_type_switcher; 
static Boolean hint2_stockview_valuation;

other variables ...
    }

then I’m using these variables anywhere across my multiple activites with …

if (Globals.hint2_stockview_valuation == false) {

        ....

    }

pretty basic and it was working fine untill …

I introduced some webview stuff like this:

//-----------------------------------------------------------
        // open a webview with the NEWS when the more_arrow is clicked :
        mNews.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                String news_URL = "http://us.m.yahoo.com/w/yfinance/symbolheadlines/"+ ticker + "/?.intl=us&.lang=en";
                Intent news_Webview_intent = new Intent(Chart_View.this, News_Webview.class);
                news_Webview_intent.putExtra("NEWS_URL", news_URL);
                startActivity(news_Webview_intent);
            }
        });
        //-----------------------------------------------------------

and here’s the News_Webview.class:

public class News_Webview extends Activity {

//
// http://www.chrisdanielson.com/tag/progressdialog/
//

String news_URL;
private WebView webview;
private ProgressDialog progressBar;
private static final String TAG = "Hub";

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.webview_news);
    this.webview = (WebView)findViewById(R.id.webView);


    Bundle extras = getIntent().getExtras();
    if (this.getIntent().getExtras()!=null){
        news_URL = extras.getString("NEWS_URL");
    }


    WebSettings settings = webview.getSettings();
    settings.setJavaScriptEnabled(true);
    webview.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);

    final AlertDialog alertDialog = new AlertDialog.Builder(this).create();

    progressBar = ProgressDialog.show(News_Webview.this, "", "Loading...");

    webview.setWebViewClient(new WebViewClient() {

        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            //Log.i(TAG, "Processing webview url click...");
            Intent viewIntent = new Intent("android.intent.action.VIEW", Uri.parse(url));  
            startActivity(viewIntent);
            return true;
        }                  

        public void onPageFinished(WebView view, String url) {
            //Log.i(TAG, "Finished loading URL: " +url);
            if (progressBar.isShowing()) {
                progressBar.dismiss();
            }
        }

        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            Log.e(TAG, "Error: " + description);
            Toast.makeText(News_Webview.this, "Oh no! " + description, Toast.LENGTH_SHORT).show();
            alertDialog.setTitle("Error");
            alertDialog.setMessage(description);
            alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    return;
                }
            });
            alertDialog.show();
        }
    });
    webview.loadUrl(news_URL);
    }
}

the problem now is that, when it “comes back” from this Activity, it looks like my Globals variables have disappeared ???

if (Globals.hint2_stockview_valuation == false) {

fires an error :

06-23 12:14:03.443:
ERROR/AndroidRuntime(2611): Caused by:
java.lang.NullPointerException

2 questions then :

  • Should I use something else than this “Global” class to share variables across activities ? Is it just bad practice to do this ?? I know that I can use the preferences but I thought it was quicker to do it this way (no need to “read” the preferences everytime I start a new activity …

  • Any idea on WHY this is happening ? Should I “get back” my savedInstanceState in some way when my activity returns from the News_Webview.class ???

As always, thank you for your help.

H.

  • 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-15T11:51:58+00:00Added an answer on May 15, 2026 at 11:51 am

    U could use intent.putExtra() for inter-activity interaction…

    One thing(just for diagnostics) i would suggest is initializing the static variables to some value and then run the App… i suppose your global class is getting re-initialized when the intent started activity returns back…

    I have used global variables, but in my case i kept them in an activity which never died. All other activities came after it and it worked perfectly fine…

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

Sidebar

Ask A Question

Stats

  • Questions 453k
  • Answers 453k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Have a look at setting the ListViewItemBackColor, you could change… May 15, 2026 at 9:34 pm
  • Editorial Team
    Editorial Team added an answer Here is a good overview: http://www.webresourcesdepot.com/php-rss-parsers/ May 15, 2026 at 9:34 pm
  • Editorial Team
    Editorial Team added an answer You can add a Post Build Event to copy the… May 15, 2026 at 9:34 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.