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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T21:24:51+00:00 2026-06-03T21:24:51+00:00

I am using a BroadCastReceiver , where receiving a BOOT_COMPLETED action. after receiving this

  • 0

I am using a BroadCastReceiver , where receiving a BOOT_COMPLETED action. after receiving this broadcast, the AlarmManager is set , and this AlarmManager fires a Notification :
The code for broadcast reciver :

package pit.opensource.events;

import java.util.Calendar;

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

public class BootReciver extends BroadcastReceiver {

    Context c;
    @Override
    public void onReceive(Context context, Intent intent) {
        // TODO Auto-generated method stub

    //  Intent i = new Intent(context,SetAlarmService.class);
    //  context.startService(i);
        setAlarm(context);
        Log.d("Alarm","Boot Reciver");

    }
    private void setAlarm(Context c){
        Log.d("Alarm","Set alarm service--------------");
        AlarmManager alarm = (AlarmManager)c.getSystemService(Service.ALARM_SERVICE);


        Calendar cal = Calendar.getInstance();

        cal.setTimeInMillis(System.currentTimeMillis());
        cal.clear();
        cal.set(2012,5,11,5,11);


        Intent i = new Intent(c,ShowNotificationService.class);
        PendingIntent pendingIntent = PendingIntent.getService(c, 12345,i, 0);

        //  alarm.set(AlarmManager.RTC_WAKEUP, dateNotif.getTime(), pendingIntent);
        //alarm.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), pendingIntent);
        alarm.set(AlarmManager.RTC_WAKEUP, 5000, pendingIntent);


        Log.d("Alarm","Alarm is alreday set*****************");

    }


}

The code for ShowNotificationService :

package pit.opensource.events;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;
import android.widget.Toast;

public class ShowNotificationService extends Service {

    @Override
    public IBinder onBind(Intent intent) {
        // TODO Auto-generated method stub
        return null;
    }
    @Override
    public void onStart(Intent intent,int startId){

        Toast.makeText(getApplicationContext(), "Alaraaaaaaaam", Toast.LENGTH_LONG).show();
        Log.d("Alarm","Notification Service");
        showNotification();
    }
    private void showNotification(){
        Intent i = new Intent(getApplicationContext(), DetailsActivity.class);

        Toast.makeText(getApplicationContext(), "Dowanlod finished!", Toast.LENGTH_LONG).show();

        int notificationID = 1;
        NotificationManager nm = (NotificationManager) getSystemService(getApplicationContext().NOTIFICATION_SERVICE);

        Log.d("Notification","Notification is set--------------------");
        PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), 0, i, 0);

        CharSequence tickerText = "Alaraaaaaaaam!";
        long when = System.currentTimeMillis();
        int icon = R.drawable.ic_launcher;

        Notification notification = new Notification(icon,tickerText,when);

        CharSequence contentTitle = "Alarm Alarm Alarm Alarm !!";
        CharSequence contentText = "Please click here to display more details";


        notification.setLatestEventInfo(getApplicationContext(), contentTitle, contentText, contentIntent);

        //---100ms delay, vibrate for 250ms, pause for 100 ms and
        // then vibrate for 500ms---
        notification.vibrate = new long[] { 100, 250, 100, 500}; // Needs vibrate permissions

        nm.notify(notificationID, notification);
    }
}
  • 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-03T21:24:52+00:00Added an answer on June 3, 2026 at 9:24 pm

    Notification is gone, because after the BroadcastReceiver is finished your application is not active any more. And notifications from non-active applications are automatically removed.

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

Sidebar

Related Questions

I am using BroadcastReceiver class for receiving the sms. My main class code is:
I want to start a service using BroadcastReceiver with this code public void onReceive(Context
Basically I want to broadcast and receive every 5 seconds using this code: private
I am using AlarmManager and NotificationManager with BroadcastReceiver . When I set an alarm
I have a BootReceiver and is using android.intent.action.BOOT_COMPLETED to reconfigure whatever alarms the user
I have a BroadcastReceiver that is using the BOOT_COMPLETED intent-filter in the AndroidManifest ,
Can an activity be invoked using a BroadcastReceiver ? The onReceive for BroadCast receiver
Has anybody experienced this? I use notification.sound to set a custom sound and a
I'm using a BroadcastReceiver to receive a Notification at a given time. Now I
I have created a Alarm using AlarmManager. Intent intent = new Intent(MyApp.this,NotificationMessage.class); PendingIntent sender

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.