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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:00:00+00:00 2026-06-15T15:00:00+00:00

as far as I can tell this should work. Except it doesn’t :-/ the

  • 0

as far as I can tell this should work. Except it doesn’t :-/

the idea is to extend all the Activity classes I use to include a BroadcastReceiver that pops up Toast Messages when I send them. The end game for this strategy is that async worker jobs can “discover for themselves” which is the “top most” form (if available) and then post messages to the uses via toast despite being part of a async event when I DO NOT CHOOSE(*) to pass the context as an argument.

The problem: when I call doDemo() the fire event happenes (I get the
log.d from doDemo()) but the receive event never fires.

(*)this is essential, it’s the whole purpose

public class ToastActivity extends Activity{
    private BroadcastReceiver ToastBroadCastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive( Context context, Intent intent ) {
            Toast.makeText(getApplicationContext(), intent.getAction() + " package: "+ intent.getPackage(), Toast.LENGTH_SHORT).show();
            Log.d("ToastBroadCastReceiver", "Broadcastreceiver: " + intent.getAction() + " package: "+ intent.getPackage() + " @" + System.currentTimeMillis());
        }
    };

    public void onResume() {
        super.onResume();
        registerReceiver(ToastBroadCastReceiver, new IntentFilter("com.my.domain.BROADCAST"));
    }

    public void onPause() {
        super.onPause();
        unregisterReceiver(ToastBroadCastReceiver);
    }

    public void doDemo(){
        Log.d("ToastBroadCastReceiver", "doDemo Broadcast started" );
        Intent broadCastIntent = new Intent();
        broadCastIntent.setAction( "com.my.domain.BROADCAST");
        broadCastIntent.setPackage( "well hello test!" );        
        sendBroadcast(broadCastIntent);
        Log.d("ToastBroadCastReceiver", "doDemo Broadcast sent" );
    }

}

EDIT

After a long conversation with Ali this is what we came up with

public class ToastActivity extends Activity{
    private BroadcastReceiver ToastBroadCastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive( Context context, Intent intent ) {

            if (intent.getAction().equals("TOASTMESSAGE")) {
                String message = "";
                Bundle extras = intent.getExtras();
                if (extras != null)            {
                    message = extras.getString("message");
                }
                Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show();
                Log.d("ToastBroadCastReceiver", "Broadcastreceiver: " + message + "|" + intent.getAction());
            }
        }
    };

    public void ToastRegister(){
        registerReceiver(ToastBroadCastReceiver, new IntentFilter("TOASTMESSAGE"));
    }

    public void ToastDeRegister(){
        try { 
            unregisterReceiver(ToastBroadCastReceiver);     
        } 
        catch (Exception e) {
            Log.e("ToastBroadCastReceiver", e.getMessage());
        }       
    }

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ToastRegister();
    }

    public void onResume() {
        super.onResume();
        ToastRegister();
    }

    public void onPause() {
        super.onPause();
        ToastDeRegister();
    }

    public void onDestroy() {
        super.onDestroy();
        ToastDeRegister();
    }

    public void doDemo(){
        Log.d("ToastBroadCastReceiver", "doDemo Broadcast started" );

        Intent broadCastIntent = new Intent();
        broadCastIntent.setAction("TOASTMESSAGE");
        broadCastIntent.putExtra("message","hello test message!");
        sendBroadcast(broadCastIntent);

        Log.d("ToastBroadCastReceiver", "doDemo Broadcast sent" );
    }

}
  • 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-15T15:00:02+00:00Added an answer on June 15, 2026 at 3:00 pm

    This line is the issue broadCastIntent.setPackage( "well hello test!" );

    edit your code like this

     broadCastIntent.setPackage( "com.my.domain.BROADCAST");
     broadCastIntent.setAction( "well hello test!" );  
    

    also replace your this line

     registerReceiver(ToastBroadCastReceiver, new IntentFilter("com.my.domain.BROADCAST"));
    

    with this

     registerReceiver(ToastBroadCastReceiver, new IntentFilter("well hello test!"));
    

    in your onReceive do like this

    if (intent.getAction().equals("well hello test!")) {
                    Update_chat_counter();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As far as I can tell, this code is fine, and should display some
I have some simple javascript that as far as i can tell should work
This is very strange because as far as I can tell the method does
I have this trigger which works functionally (as far as I can tell by
As far as I can tell i'm doing everything by the book, but the
As far as I can tell, there is no API (official or unofficial) to
As far as I can tell, Scala has definitions for the Enumeration Value class
As far as I can tell I wouldn't think it would make any difference
That's basically it, as far as I can tell. I can include or require_once
I am an MVC newbie. As far as I can tell: Controller : deals

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.