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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:32:56+00:00 2026-06-14T22:32:56+00:00

I have a class that extends BroadCastReceiever and the onReceive Method is the following:

  • 0

I have a class that extends BroadCastReceiever and the onReceive Method is the following:

public class Alarm extends BroadcastReceiver
{
    @Override
    public void onReceive(Context context, Intent intent)
    {
        String message = intent.getStringExtra("message2");
        Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
        Intent intent1 = new Intent(context, AlarmShow.class);
        context.startActivity(intent1);

    }
}

But it crashes everytime it runs the onReceive method instead of starting the activity in the intent.

Ive tried almost everything.

Any help would be appreciated.

Thanks

EDIT: LogCat Errors:

11-25 18:24:00.511: D/AndroidRuntime(2158): Shutting down VM
11-25 18:24:00.511: W/dalvikvm(2158): threadid=1: thread exiting with uncaught exception (group=0x40015560)
11-25 18:24:00.521: E/AndroidRuntime(2158): FATAL EXCEPTION: main
11-25 18:24:00.521: E/AndroidRuntime(2158): java.lang.RuntimeException: Unable to start receiver com.example.androidalarm.Alarm: android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity  context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
11-25 18:24:00.521: E/AndroidRuntime(2158):     at android.app.ActivityThread.handleReceiver(ActivityThread.java:1805)
11-25 18:24:00.521: E/AndroidRuntime(2158):     at android.app.ActivityThread.access$2400(ActivityThread.java:117)
11-25 18:24:00.521: E/AndroidRuntime(2158):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:981)
11-25 18:24:00.521: E/AndroidRuntime(2158):     at android.os.Handler.dispatchMessage(Handler.java:99)
11-25 18:24:00.521: E/AndroidRuntime(2158):     at android.os.Looper.loop(Looper.java:123)
11-25 18:24:00.521: E/AndroidRuntime(2158):     at android.app.ActivityThread.main(ActivityThread.java:3683)
11-25 18:24:00.521: E/AndroidRuntime(2158):     at java.lang.reflect.Method.invokeNative(Native Method)
11-25 18:24:00.521: E/AndroidRuntime(2158):     at java.lang.reflect.Method.invoke(Method.java:507)
11-25 18:24:00.521: E/AndroidRuntime(2158):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
11-25 18:24:00.521: E/AndroidRuntime(2158):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
11-25 18:24:00.521: E/AndroidRuntime(2158):     at dalvik.system.NativeStart.main(Native Method)
11-25 18:24:00.521: E/AndroidRuntime(2158): Caused by: android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity  context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
11-25 18:24:00.521: E/AndroidRuntime(2158):     at android.app.ContextImpl.startActivity(ContextImpl.java:621)
11-25 18:24:00.521: E/AndroidRuntime(2158):     at android.content.ContextWrapper.startActivity(ContextWrapper.java:258)
11-25 18:24:00.521: E/AndroidRuntime(2158):     at android.content.ContextWrapper.startActivity(ContextWrapper.java:258)
11-25 18:24:00.521: E/AndroidRuntime(2158):     at com.example.androidalarm.Alarm.onReceive(Alarm.java:20)
11-25 18:24:00.521: E/AndroidRuntime(2158):     at android.app.ActivityThread.handleReceiver(ActivityThread.java:1794)
11-25 18:24:00.521: E/AndroidRuntime(2158):     ... 10 more
11-25 18:24:02.611: I/Process(2158): Sending signal. PID: 2158 SIG: 9
  • 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-14T22:32:57+00:00Added an answer on June 14, 2026 at 10:32 pm

    Test message is not null or you will have a nullPointerException.
    Also if you aren’t use this under activity you need :

    intent.addFlag(Intent.FLAG_ACTIVITY_NEW_TASK);
    

    Or you will also have a crash.

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

Sidebar

Related Questions

I have the following broadcast receiver: public class MyRingModeReceiver extends BroadcastReceiver { @Override public
Inside of the onReceive(Content context, Intent intent) method of my public class MediaButtonIntentReceiver extends
I have a class that extends View. I override the onDraw method and allow
I have a Sms Broadcast Receiver class that extends broadcastreceiver to handle incoming sms,
I have a class that extends AsyncTask. In the doInBackground() method, I connect to
I have an application that calls AlarmManager Intent intent; intent = new Intent(context, MyEventReceiver.class);
If I have an inner class that extends BroadcastReceiver within my Service class, should
I have an class as below: public class FYPSmsReceiverBroadcast extends BroadcastReceiver I need to
I have a class that extends AsyncTask , which fetches the gps cordinates from
I have a class that extends Application. The class is fairly extensive. When the

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.