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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:01:14+00:00 2026-06-12T19:01:14+00:00

I am developing an application in android and using BroadcastReceiver class to override the

  • 0

I am developing an application in android and using BroadcastReceiver class to override the method onReceive. But my application is closing unexpectedly when an SMS comes. The code is shown below.

package com.jb.blinkme;
import android.os.Bundle;
import android.os.Handler;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.telephony.SmsMessage;
import android.view.Menu;
import android.widget.Toast;

public class BlinkMe extends Activity {

private static final int LED_NOTIFICATION_ID = 33;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_blink_me);
    RedFlashLight();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_blink_me, menu);
    return true;
}
public void RedFlashLight() {
    NotificationManager nm = ( NotificationManager ) getSystemService( NOTIFICATION_SERVICE );
    Notification notif = new Notification();
    notif.ledARGB = 0xF7FE2E;
    notif.flags = Notification.FLAG_SHOW_LIGHTS;
    notif.ledOnMS = 1000; 
    notif.ledOffMS = 1000; 
    nm.notify(LED_NOTIFICATION_ID, notif);
    Handler myHandler = new Handler();
    myHandler.postDelayed(mClearLED_Task, 10000);
}
public void ClearLED() {
    NotificationManager nm = ( NotificationManager ) getSystemService( NOTIFICATION_SERVICE );
    nm.cancel( LED_NOTIFICATION_ID );
}
public Runnable mClearLED_Task = new Runnable() {
    public void run() {
        ClearLED();
    }
};

}

package com.jb.blinkme;
import android.content.BroadcastReceiver;
import android.os.Bundle;
import android.content.Context;
import android.content.Intent;
import android.telephony.SmsMessage;
import android.widget.Toast;

public class SMSReceiver extends BroadcastReceiver {

/**
 * @see android.content.BroadcastReceiver#onReceive(android.content.Context, android.content.Intent)
 */
@Override
public void onReceive(Context context, Intent intent) {
    BlinkMe blink = new BlinkMe();
    blink.RedFlashLight();

}
}

and my manifest file is

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.jb.blinkme"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme"
    android:debuggable="true" >
    <activity
        android:name=".BlinkMe"
        android:label="@string/title_activity_blink_me" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <receiver android:name=".SMSReceiver" android:enabled="true">
        <intent-filter>
            <action android:name="android.provider.Telephony.SMS_RECEIVED" />
        </intent-filter>
    </receiver>
</application>

But while running the application, It is closing unexpectedly and I am getting the following error from LogCat.

10-10 23:38:53.410: E/AndroidRuntime(6248): FATAL EXCEPTION: main
10-10 23:38:53.410: E/AndroidRuntime(6248): java.lang.RuntimeException: Unable to start receiver com.jb.blinkme.SMSReceiver: java.lang.IllegalStateException: System services not available to Activities before onCreate()
10-10 23:38:53.410: E/AndroidRuntime(6248):     at android.app.ActivityThread.handleReceiver(ActivityThread.java:2146)
10-10 23:38:53.410: E/AndroidRuntime(6248):     at android.app.ActivityThread.access$1500(ActivityThread.java:127)
10-10 23:38:53.410: E/AndroidRuntime(6248):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1208)
10-10 23:38:53.410: E/AndroidRuntime(6248):     at android.os.Handler.dispatchMessage(Handler.java:99)
10-10 23:38:53.410: E/AndroidRuntime(6248):     at android.os.Looper.loop(Looper.java:137)
10-10 23:38:53.410: E/AndroidRuntime(6248):     at android.app.ActivityThread.main(ActivityThread.java:4441)
10-10 23:38:53.410: E/AndroidRuntime(6248):     at java.lang.reflect.Method.invokeNative(Native Method)
10-10 23:38:53.410: E/AndroidRuntime(6248):     at java.lang.reflect.Method.invoke(Method.java:511)
10-10 23:38:53.410: E/AndroidRuntime(6248):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
10-10 23:38:53.410: E/AndroidRuntime(6248):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
10-10 23:38:53.410: E/AndroidRuntime(6248):     at dalvik.system.NativeStart.main(Native Method)
10-10 23:38:53.410: E/AndroidRuntime(6248): Caused by: java.lang.IllegalStateException: System services not available to Activities before onCreate()
10-10 23:38:53.410: E/AndroidRuntime(6248):     at android.app.Activity.getSystemService(Activity.java:3989)
10-10 23:38:53.410: E/AndroidRuntime(6248):     at com.jb.blinkme.BlinkMe.RedFlashLight(BlinkMe.java:32)
10-10 23:38:53.410: E/AndroidRuntime(6248):     at com.jb.blinkme.SMSReceiver.onReceive(SMSReceiver.java:18)
10-10 23:38:53.410: E/AndroidRuntime(6248):     at android.app.ActivityThread.handleReceiver(ActivityThread.java:2139)
10-10 23:38:53.410: E/AndroidRuntime(6248):     ... 10 more

Is there anything wrong?

Thanks in advance.

  • 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-12T19:01:15+00:00Added an answer on June 12, 2026 at 7:01 pm
    BlinkMe blink = new BlinkMe();
    blink.RedFlashLight(); 
    

    That is wrong in your onReceive. You can’t create an instance like this for Activity since it is not a Class.

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

Sidebar

Related Questions

I am developing an android app using code from a normal java application. In
I am developing a chat application for Android, using AIR/Flex and Red5. But Acoustic
I'm developing application for android by using flex. That app should read sms from
The code (android application) I am developing receives an SMS and if the SMS
I am developing an application in Android using Eclipse. I wrote the following code
I'm developing android application using HTML5, jQuery and Phonegap. But i'm not able to
I am developing an application using Android SDK. In this application I am facing
I am currently developing an android application using eclipse and I already have a
So im developing a android application and im using a tabhost. To handle the
I'm developing an Android application which sends content to a server using rest web

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.