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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:09:21+00:00 2026-06-11T23:09:21+00:00

Since fragments are intended to encapsulate logic I decided to put BroadReceiver logic in

  • 0

Since fragments are intended to encapsulate logic I decided to put BroadReceiver logic in my own fragment.

At first I setup an Alarm like it was shown in ApiDemos:

Intent intent = new Intent(getActivity(),OnAirPresentBroadcastReceiver.class);
PendingIntent sender = PendingIntent.getBroadcast(getActivity(), 0, intent, 0);

Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.add(Calendar.SECOND, 30);

AlarmManager am = (AlarmManager) getActivity().getSystemService(Context.ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), sender);

OnAirPresentBroadcastReceiver receives the broadcast and the purpose of this broadcast is to update the fragment’s UI. I’m stuck here – is it possible and how ?

  • 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-11T23:09:22+00:00Added an answer on June 11, 2026 at 11:09 pm

    From your Receiver you can post another Intent to your Activity. From the Activity you can access the Fragment with the FragmentManager.

    Intent notificationIntent = new Intent(context, MainActivity.class);
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
    notificationIntent.putExtra("extra", "extra");
    context.startActivityForResult(notificationIntent, 0);
    

    It’ll you’ll get it on your Activity in:

    @Override
    protected void onNewIntent(Intent intent)
    {
        handleNotification(intent);
    
        super.onNewIntent(intent);
    }
    

    If your Activity is not running you’ll have Extra’s to your intent in OnCreate

    To make sure your Activity is in foreground: (this code get the foreground Activity)

    ActivityManager am = (ActivityManager) context.getSystemService(Activity.ACTIVITY_SERVICE);
    List<ActivityManager.RunningTaskInfo> taskInfo = am.getRunningTasks(1);
    String name = taskInfo.get(0).topActivity.getShortClassName();
    if (name.equals(".YOUR_ACTIVITY_NAME")) 
        {
        //only now start your intent.
        }
    

    Another direction you can try:

    Intent intent = new Intent(getActivity(),YOUR_ACTIVITY_HERE.class);
    PendingIntent sender = PendingIntent.getActivitygetActivity(), 0, intent, 0);
    

    Now the event you come in your Activity’s onNewIntent function, if its active. That’s not a full solution but that could be a nice direction.

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

Sidebar

Related Questions

Since each thread has its own stack, its private data can be put on
I would like to use tabs in my Android application and since TabActivity is
I wanted to use an ExpandableListView for my Fragment but since it's not native,
First, I apologise for my English since it's not really good. Thanks. My application
Hi I'm working with a view pager and fragments. I would like to override
I'm creating a tablet optimised application using fragments. I have a thin navigation fragment
The only documented way I found is: MyFragment fragment = (MyFragment) getSupportFragmentManager().findFragmentById(R.id.fragment); But since
since memcpy should be highly optimized nowadays, does it still make sense to optimize
Since regular jQuery animations are not fluent on iOS ( .hide() , slideDown() ),
since today im facing a strange problem. When i start my app in my

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.