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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:26:07+00:00 2026-06-02T03:26:07+00:00

I have a BroadcastReceiver that I’m using to send data to another activity which

  • 0

I have a BroadcastReceiver that I’m using to send data to another activity which may or may not be running. I’m using the intent in my onReceive() method, and putting the data in with putExtra(). THe data gets sent to the activity, however, the activity’s onCreate() method gets called even though the activity is already running and in the foreground, so I guess it’s creating a new instance. I want to only have onResume() called, or perhaps there’s some other way I can create/start the intent if it doesn’t exist, and if it does, just have it ‘resumed’. Right now, the activity is being recreated, and I do not want this.

public void onReceive(Context context, Intent intent) {
            intent.setClass(context, MyActivity.class);
            intent.putExtra("message", "the data here");
            //intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            Log.d("sending msg", "msg");    
            context.startActivity(intent);    
       }

If I do not use FLAG_ACTIVITY_NEW_TASK, a RuntimeException is throw, specifically telling me that if I want to start an activity from something that is not an activity, I must use FLAG_ACTIVITY_NEW_TASK.

  • 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-02T03:26:08+00:00Added an answer on June 2, 2026 at 3:26 am

    I ended up rebroadcasting (internally) the parsed information that my BroadcastReceiver was getting in. The actvity, in code, registered for the event and had a small handler method in a private-created receiver. This was a good solution as I know that this activity would always be running in my case.

        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
    
            receiver = new BroadcastReceiver(){
    
                @Override
                public void onReceive(Context context, Intent intent) {
                    Log.d("activity", "in local defined receiver");
                    if(intent.getAction().equals(CustomInternalSendSmsAction) )
                    {
                        handlePassedData(intent);               
                    }
                }
            };
            this.registerReceiver(receiver, new IntentFilter(CustomInternalSendSmsAction));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Alarm Manager which send Intent to BroadcastReceiver. This Broadcast is not
Is it possible that BroadcastReceiver in an activity which have gone to background receiving
I have an application, which sets an alarm using AlarmManager, which starts another Activity
I have a BroadcastReceiver that is using the BOOT_COMPLETED intent-filter in the AndroidManifest ,
I have a BroadcastReceiver that listen for the SMS_SENT Intent after an SMS has
I have an activity that starts a service like that: Intent youtubeIntent = new
I have a BroadcastReceiver that reacts on BOOT_COMPLETED. In turn it shall issue an
I have a BroadcastReceiver that listens for incoming sms messages. While a new sms
I have on Service that must communicate with an Activity (MyActivity) through a BradcastReceiver.
I have an BroadcastReceiver for handling new or modified applications: <receiver android:name=.PackageHandler > <intent-filter>

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.