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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:25:23+00:00 2026-05-28T06:25:23+00:00

This is my code: Activity: @Override public void onCreate(Bundle savedInstanceState) { … Intent intent

  • 0

This is my code:

Activity:

@Override
public void onCreate(Bundle savedInstanceState) {

...

Intent intent = new Intent(this, MyReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(
    this.getApplicationContext(), 234324243, intent, PendingIntent.FLAG_UPDATE_CURRENT);

AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);

alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()
    + (5 * 1000), pendingIntent);

...
} 

BroadcastReceiver:

public class MyReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
    Intent service = new Intent(context, StartNotificationService.class);

    context.startService(service);
}

Service:

public class StartNotificationService extends Service {

@Override
public void onStart(Intent intent, int startId) {
    super.onStart(intent, startId);

    this.intent = intent;
    showNotification();
}

private void showNotification() {
    Date date = new Date(pror.getFirstMillis());

    Log.i("date", date.toString());

    Timer timer = new Timer();
    TimerTask timerTask = new TimerTask() {
        @Override
        public void run() {
            createNotification(contentTitle, contentText, tickerText);

            pror.calculateVak();
            pror.setFirstMillis(pror.getNextVak());

            createStatusBarNotification(contentTitle, contentText, tickerText);
        }
    };
    timer.schedule(timerTask, date);
}

}

AndroidManifest

<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
     android:icon="@drawable/icon"
    android:label="@string/app_name" >
    <activity android:name=".ShowSettingsActivity" />

    <receiver android:name=".MyReceiver"/> 
    <service android:name=".service.StartNotificationService"/>

    <activity android:name=".PreferencesActivity" android:label="@string/app_name">
   </activity>
    <activity
        android:label="@string/app_name"
        android:name=".VakActivity" >
        <intent-filter >
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

When phone go to sleep, alarmManager can’t start notification/service.

If I leave my phone in the ‘active’ – unlock state, a notification is triggered at a certain time.

Where I made mistake?

  • 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-28T06:25:24+00:00Added an answer on May 28, 2026 at 6:25 am

    There are two ways to approach it.

    1. If all you’re doing is creating a status bar notification, then just do that in your BroadcastReceiver
    2. If you need your service to run prior to making the notification, and you need this to be able to happen while device is asleep, you need to acquire a WAKE_LOCK

    So for approach 2 in your class body for the service you need:

    PowerManager pm;
    PowerManager.WakeLock wl;
    

    Then in your onCreate you need:

    pm = (PowerManager)getSystemService(Context.POWER_SERVICE);
    wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "My Tag");
    wl.acquire();
    

    And then in your onDestroy you need to put:

    wl.release();
    

    All this info I got from PowerManager

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

Sidebar

Related Questions

I have this code: public class Home extends Activity{ @Override public void onCreate(Bundle savedInstanceState)
public class screen2 extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.screen2);
I have the following code in one activity: in= new Intent(ThisActivity.this,AnotherActivity.class); imgarr = new
This code isn't work. What happen? public class Main extends Activity { /** Called
Hey Guys i got this code in my Activity: public class MYAppActivity extends Activity{
I have this code: public class VoiceActivity extends Activity implements OnClickListener { private TextView
I have this code: public class Chronom extends Activity { Chronometer mChronometer; ProgressBar progre;
this is my first activity code: public class hello extends Activity { /** Called
This code: public class MyActivity extends Activity { private final boolean logging = getResources().getBoolean(R.bool.logging);
I wrote this code in order to make a soundboard like app public class

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.