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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:12:39+00:00 2026-05-16T14:12:39+00:00

I am new to android. I what to know the difference between Intent and

  • 0

I am new to android. I what to know the difference between Intent and BroadcastReceiver. I am more confused with BroadcastReceiver than Intent.

Please help me out. Simple code will be helpful.

  • 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-16T14:12:39+00:00Added an answer on May 16, 2026 at 2:12 pm

    Ok, I will explain it with an example.

    Let’s suppose I want to create an app to check subway status from it’s webpage. I also want a system notification if the subway is not working ok.

    I will have:

    • An Activity to show results.
    • A Service to check if the subway is working and show a notification if it’s not working.
    • A Broadcast Receiver called Alarm Receiver to call the service every 15 minutes.

    Let me show you some code:

    /* AlarmReceiver.java */
    public class AlarmReceiver extends BroadcastReceiver {
        public static final String ACTION_REFRESH_SUBWAY_ALARM =
              "com.x.ACTION_REFRESH_SUBWAY_ALARM";
    
        @Override
        public void onReceive(Context context, Intent intent) {
            Intent startIntent = new Intent(context, StatusService.class);
            context.startService(startIntent);
        }
    }
    

    Explanation:
    As you can see you can set an alarm. and when the alarm is received we use an intent to start the service. Basically the intent is a msg which can have actions, an serialized stuff.

    public class StatusService extends Service {
    
        @Override
        public void onCreate() {
            super.onCreate();
            mAlarms = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
            Intent intentToFire = new Intent(AlarmReceiver.ACTION_REFRESH_ALARM);
            mAlarmIntent = PendingIntent.getBroadcast(this, 0, intentToFire, 0);
        }
    
        @Override
        public void onStart(Intent intent, int arg1) {
            super.onStart(intent, arg1);
            Log.d(TAG, "SERVICE STARTED");
            setAlarm();
            Log.d(TAG, "Performing update!");
            new SubwayAsyncTask().execute();
            stopSelf();
        }
    
        private void setAlarm() {
            int alarmType = AlarmManager.ELAPSED_REALTIME_WAKEUP;
            mAlarms.setInexactRepeating(alarmType, SystemClock.elapsedRealtime() + timeToRefresh(),
                        AlarmManager.INTERVAL_HALF_DAY, mAlarmIntent);
        }
    
    }
    

    Explanation:

    The service starts and:

    • Set the alarm for the next call. (Check the intent it’s used. Just a msg)
    • Calls an AsyncTask which takes care of updating an notifying the Activity

    It doesn’t make sense to paste the AsyncTask but when it finished it calls:

    private void sendSubwayUpdates(LinkedList<Subway> subways) {
          Intent intent = new Intent(NEW_SUBWAYS_STATUS);
          intent.putExtra("subways", subways);
    
          sendBroadcast(intent);
    }
    

    This creates a new Intent with a certain NEW_SUBWAYS_STATUS action, put inside the intent the subways and sendBroadcast. If someone is interested in getting that info, it will have a receiver.

    I hope I made myself clear.

    PS: Some days ago someone explained broadcast and intents in a very cool way.
    Someone wants to share his beer, so he sends a broadcast
    with an intent having action:”FREE_BEER” and with an extra: “A glass of beer”.

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

Sidebar

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.