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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T15:12:19+00:00 2026-05-29T15:12:19+00:00

I just changed my external broadcast receiver class to my service since..some android method

  • 0

I just changed my external broadcast receiver class to my service since..some android method could not be used in static context. Now i receive an error Unable to instantiate activity ComponentInfo{com…}: java.lang.NullPointerException. How is it possible to fix? Below is my code for nested BroadcastReceiver class.

public class ServiceX extends Service {

private SharedPreferences settings = getSharedPreferences(PREFS, 0);
private SharedPreferences.Editor editor = settings.edit();

private static void setEnableNotification(int command) {
    if (command == 1)
        enableNotification = true;
    else
        enableNotification = false;

    editor.putBoolean("enableNotification", enableNotification);
      editor.commit();
}

public static class ReceiverX extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
            int enableNotification = intent.getIntExtra("EnableNotification", 0);

            if (enableNotification == 0)
                context.
                setEnableNotification(0);
            else if (enableNotification == 1)
                setEnableNotification(1);

}

}

Below is how i instansiated the inner class:

public class ActivityX extends Activity{

private BroadcastReceiver receiver = security365Service.new NotifyServiceReceiver();

Here below is my mainfest which i changed after looking at some sources online:

    <receiver android:name="com.milanix.services.ServiceX$ReceiverX" android:enabled="true">
    </receiver>

Sorry if my question is dumb.

  • 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-29T15:12:20+00:00Added an answer on May 29, 2026 at 3:12 pm

    You cannot use a regular inner class here. It would need to be a static inner class, which will get you back to your original problem. So, you need to solve your “some android method could not be used in static context” problem one way or another.

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

Sidebar

Related Questions

Hi I am using Mysql 5.0.x I have just changed a lot of the
I want to workaround the Webpage has expired issue. First, I just changed a
I just recently changed out all my hard drives and in the process of
I have just installed a new ssl certificate on GlassFish 3. I also changed
I'm using Shared Linux hosting and some PHP I wrote just won't work with
I am successfully loading via AJAX some svg from external file: $(#svg).load(svgUrl + svg,
I am having some issues with WPF not fully repainting a button control when
I just enabled Failed Request Tracing for a site and I get a URL_CHANGED
I figured the easiest thing to do was to just change the port number
Why won't the following C code compile? It seems like it should just change

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.