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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:06:16+00:00 2026-05-20T18:06:16+00:00

In my application there are two class one is InternetActivity which only extends Activity

  • 0

In my application there are two class one is InternetActivity which only extends Activity and sets contentview to main. and MyClass that extends broadcast receiver.

I have 2 TextView and 2 ImageView of WIFI and GPRS in main.xml file.
When changes in connectivities are happening,brodcast receiver is getting called and according to what is enabled and what is not i want to set visibility of TextView and ImageView. But it is only showing both the images and not the changes.
here is MyClass.java file. how can i do it??

public class MyClass extends BroadcastReceiver {

private static ImageView wifi_image, gprs_image;
private static TextView wifi_text, gprs_text;

@Override
public void onReceive(Context context, Intent intent) {

    Log.i("IntrntActivity", "Broadcast message receivved");

    LinearLayout layout = new LinearLayout(context);
    LinearLayout.LayoutParams params = new LayoutParams(
            LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

    View view = View.inflate(context, R.layout.main, layout);

    wifi_image = (ImageView) view.findViewById(R.id.wifi_image);
    gprs_image = (ImageView) view.findViewById(R.id.gprs_image);

    wifi_text = (TextView) view.findViewById(R.id.wifi_text);
    gprs_text = (TextView) view.findViewById(R.id.gprs_text);

    wifi_image.setVisibility(View.GONE);
    wifi_text.setVisibility(View.GONE);
    gprs_image.setVisibility(View.GONE);
    gprs_text.setVisibility(View.GONE);

    ConnectivityManager cm = (ConnectivityManager) context
            .getSystemService(context.CONNECTIVITY_SERVICE);
    NetworkInfo WIFI = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    NetworkInfo Mobile = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);

    if (!WIFI.isConnected() && WIFI.isAvailable()) {
        Toast.makeText(context, "WIFI is available but not connected",
                Toast.LENGTH_LONG).show();
    }

    if (cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isAvailable()) {
        wifi_image.setVisibility(View.VISIBLE);
        wifi_text.setVisibility(View.VISIBLE);

    }

    if (Mobile.isConnected()) {
        gprs_image.setVisibility(View.VISIBLE);
        gprs_text.setVisibility(View.VISIBLE);
        Log.i("IntrntActivity", "Mobile isConnected");

        // Toast.makeText(context,"GPRS is available",
        // Toast.LENGTH_LONG).show();
    }

    if (!Mobile.isConnected()) {
        gprs_image.setVisibility(View.GONE);
        gprs_text.setVisibility(View.GONE);
        Log.i("IntrntActivity", "Mobile is Not Connected");
        // Toast.makeText(context,"GPRS is available",
        // Toast.LENGTH_LONG).show();
    }


}

}

P.S : It is correctly going in Mobile.isConnected() and !Mobile.isConnected() and showing it in Log file but its Visibility is not changing.Am i not setting the view correctly? and is it possible to call setContentView(view) from this broadcast receiver?

  • 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-20T18:06:17+00:00Added an answer on May 20, 2026 at 6:06 pm

    You need to put your reciever into InternetActivity class, register it there and use already defined local variables. You need not to create separate public BroadcastReceiver implementation, just do a local one.

    Like this:

    import android.content.BroadcastReceiver;
    import android.content.Context;
    
    public class InternetActivity extends Activity {
    
        private ImageView image;
        private TextView text;
    
        private BroadcastReceiver reciever = new BroadcastReceiver(){
            @Override
            public void onReceive(Context context, Intent intent) {
               // do all the checking
               // interact with image and text
            }    
        };
        @Override
        public void onCreate(Bundle state) {
            setContentView(R.layout.....);
            // fill in image and text variables
        }
        @Override
        public void onStart() {
            registerReceiver(receiver, /* your intent filter here */);
        }
        @Override
        public void onStop() {
            unregisterReceiver(receiver);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Backdrop: There are two forms, the main application form and a form to edit
In my web application there is a process that queries data from all over
In the application there is a dialog where only numeric string entries are valid.
I'm working on a Wicket-based web application. In the application there are buttons that
Is there an application out there that Generates an HTML form from a PDF
In an MFC application there is a small rectangular region where the scroll bars
For my application there are several entity classes, User, Customer, Post, and so on
I know there are several ways to deploy a .net windows client application: There's
we need reports in our web application and there is the free ReportViewer Control
During the course of our application login there are several queries ran, all around

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.