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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:26:12+00:00 2026-06-17T16:26:12+00:00

hi i have created a global actions class and created functions inside this class

  • 0

hi i have created a global actions class and created functions inside this class which i’m trying to access inside another activity the problem i’m having is that in eclipse I’m getting coding errors around the functions that access system feature such as getSystemService() and getApplicationContext() does anyone know why or how to let a global class accept system features?

heres what i have so far heres my GloblActions.java

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.util.Log;

public class GlobalActions{
        Context mContext;

        // constructor
        public GlobalActions(Context context){
            this.mContext = context;
        }


        public final static boolean isOnline (Context someContext){ {

            Log.v("globals", "isonline");

    ConnectivityManager cm = (ConnectivityManager) someContext.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo netInfo = cm.getActiveNetworkInfo();

        if (netInfo != null && netInfo.isConnectedOrConnecting()) {
            return true;
        }
        return false;
        }

}



        public final static void checkInternet(Context someContext){

                    isOnline(someContext);
                    if(isOnline(someContext) == false){
                       Log.v("globals", "isOnline = false");
                       Intent register = new Intent(someContext.getApplicationContext(), LoginForm.class);
                       someContext.startActivity(register);
                    }
                }



        }   

heres where i’m using the function in an activity. my goal is is to check internet connection on every activity by just calling the global function and if no connection is found go to an activity that says no internet connection.

import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.TextView;
import android.os.Handler;
import com.myApp.myApp.GlobalActions;

public class IntroLoader extends Activity {

    public Handler handler;
    public TextView loadText = null;
    public Animation AniFadein = null;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.lo_introloader);
        findViewById(R.id.progressBar1).setVisibility(View.GONE);
        findViewById(R.id.loadTextView).setVisibility(View.GONE);
         GlobalActions.isOnline(null);
         GlobalActions.checkInternet(null);

        handler = new Handler();
        final Runnable fadeIn = new Runnable()
        {
            public void run() 
            {
               animations();
               findViewById(R.id.progressBar1).setVisibility(View.VISIBLE);
               findViewById(R.id.loadTextView).setVisibility(View.VISIBLE);
                         }
        };
        handler.postDelayed(fadeIn, 3000);

        final Runnable aSyncTask= new Runnable()
        {
            public void run() 
            {

               PostTask posttask;
               posttask = new PostTask();
               posttask.execute();

            }
        };
        handler.postDelayed(aSyncTask, 4000);

    }

    public void animations(){

        loadText = (TextView)findViewById(R.id.loadTextView);
        AniFadein = AnimationUtils.loadAnimation(this, R.anim.fadein);  
        loadText.startAnimation(AniFadein); 

    }


  public class PostTask extends AsyncTask<Void, String, Boolean> {

        protected void onPreExecute() {
            super.onPreExecute();

        }

        @Override
        protected Boolean doInBackground(Void... params) {
            boolean result = false;
            publishProgress("progress");
            return result;
        }

        protected void onProgressUpdate(String... progress) {
            StringBuilder str = new StringBuilder();
                for (int i = 1; i < progress.length; i++) {
                    str.append(progress[i] + " ");

                }
        }

            @Override
        protected void onPostExecute(Boolean result) {
            super.onPostExecute(result);
            checkLoginData();
          }
    }

  public void checkLoginData(){

      Intent register = new Intent(getApplicationContext(), LoginForm.class);
      startActivity(register);


  }         



}
  • 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-17T16:26:14+00:00Added an answer on June 17, 2026 at 4:26 pm

    Do

     ConnectivityManager cm = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
    

    Contexts can use the method getSystemService() but your class isn’t a Context, you need to use your mContext variable.

    This means that you can also replace getApplicationContext() with mContext. And if you really need getApplicationContext() (unlikely – normal Contexts should work fine), use

    mContext.getApplicationContext()
    

    Also, you declare your isOnline() method as static, but then you need to use a Context for checking and making the toast. Either don’t make it static or change it so it accepts in a Context, eg

    public final static boolean isOnline (Context someContext){
    

    And replace calls there that need a Context with someContext. Static methods don’t need an instance of the class, and so, you can’t use mContext. Once you fix the getApplicationContext() issue you have now, the compiler should throw an error about accessing a non static field in a static way. Same with your checkInternet(). I suggest you revaluate your logic, there are multiple problems with your class – I suggest making everything a static method that accepts in a Context which will be given by the calling Activity.

    Lastly be careful about showing Toasts and other UI Elements in a global non-ui class. Toasts should be fine since they run on top of windows, but a Dialog will need a window, and if mContext is not an instance of Activity, that will fail (Activities have a window, other Contexts (like getApplicationContext()), do not.

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

Sidebar

Related Questions

So I have created a global class which extends globalsettings: public class Global extends
I am using my admin panel login script where i have created a global.php
I have such problem: I have 2 custom components, which have their own nesting
I have created a custom module and am trying to include a block just
I have looked at past questions on this but I can't solve my problem
So I have a bit of a problem. I have created a drag and
I created MVC Application that have 3 different Area. (Admin, User, News) This is
Here is a situation, I have an android activity which starts a service (The
I have a string like following: CREATE GLOBAL TEMPORARY TABLE some_temp_table_name or CREATE GLOBAL
I have a sample file like the following: CREATE GLOBAL TEMPORARY TABLE tt_temp_user_11 (

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.