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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:14:47+00:00 2026-06-13T04:14:47+00:00

I never worked with Services before. So, after following few demons on internet my

  • 0

I never worked with Services before. So, after following few demons on internet my implementation is this:

In my MainActivity’s onResume() I am starting the Service this way:

protected void onResume() {
super.onResume();
startService(new Intent(MainActivity.this, NotificationsService.class));
AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
Intent i = new Intent(this, NotificationsService.class);
PendingIntent pi = PendingIntent.getService(this, 0, i, 0);
am.cancel(pi);
am.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
SystemClock.elapsedRealtime() + 60000, 60000, pi);
}

And my NotificationsService Class is:

public class NotificationsService extends Service {

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        handleIntent(intent);
        return START_NOT_STICKY;
    }
    private NotificationManager nm;
    private WakeLock mWakeLock;

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

    @Override
    public void onDestroy() {
        super.onDestroy();
        mWakeLock.release();
    }

    private void showNotification() {

        nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        Notification notification = new Notification(R.drawable.icon,
                "Notification Ticker", System.currentTimeMillis());
        notification.flags = Notification.FLAG_AUTO_CANCEL;
        Date date = new Date(System.currentTimeMillis());
        Intent i = new Intent(this, NotificationsActivity.class);
        i.putExtra("notification",
                "This is the Notification " + date);
        i.putExtra("notifiedby", "xyz");
        PendingIntent contentIntent = PendingIntent.getActivity(this, 0, i,
                PendingIntent.FLAG_UPDATE_CURRENT);
        notification.setLatestEventInfo(this, "xyz",
                "This is the Notification", contentIntent);
        nm.notify(R.string.service_started, notification);
    }

    private class PollTask extends AsyncTask<Void, Void, Void> {

        @Override
        protected Void doInBackground(Void... params) {
            showNotification();
            return null;
        }

        @Override
        protected void onPostExecute(Void result) {
            stopSelf();
        }
    }

    private void handleIntent(Intent intent) {
        // obtain the wake lock
        PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE);
        mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
                "NotificationsService");
        mWakeLock.acquire();
        // check the global background data setting
        ConnectivityManager cm = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
        if (!cm.getBackgroundDataSetting()) {
            stopSelf();
            return;
        }
        new PollTask().execute();
    }
}

In the NotificationsActivity I am getting the Extras and showing the. These Extras have a time stamp and I am calling the showNotifications() method once every minute (60000 ms).

Problem:

  1. The time stamp I am showing in the NotificationsActivity, which I get from the Service Extras is the TimeStamp of the 1st Notification

E.g., if it’s 10:10:10 A.M for the 1st notification it’s been always 10:10:10 A.M in the Activity. But in the Notifications panel it’s showing the updated one like 10:15:10 A.M for every Notification created every minute.

  1. If I am setting the Notification every minute, I expect the Notifications to be separate. Instead it is just replacing the previous Notification. Or best would be like 10 Notifications from myApp.

How to get these?

Mainly I want to know why the timestamp not getting updated?

  • 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-13T04:14:48+00:00Added an answer on June 13, 2026 at 4:14 am

    The time stamp i am showing in the NotificationsActivity, which i get from the Service Extras i the TimeStamp of the 1st Notification

    If the activity was still running, it should be called with onNewIntent() instead of onCreate(), and the Intent delivered to onNewIntent() should have the appropriate extras. getIntent() always returns the Intent used to create the activity in the first place.

    If i am setting the Notification Every minute, I expect the Notifications to be separate.

    Users think that developers who flood their screen with notifications to be complete imbeciles.

    Instead it is just replacing the previous Notification.

    That is what you are telling it to do with your call to notify().

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

Sidebar

Related Questions

I have never worked with web services and rails, and obviously this is something
I've never worked with the registry before and it seems a bit intimidating, as
I have inherited a SSIS project. I have never worked with SSIS before, and
I successfully installed the latest QuantumGrid from DevExpress, but I've never worked with this
This is probably a really simple question but one I've never quite worked out
I never worked with Silverlight before, but I have the requirement to build a
i never worked with Reporting Services in the past and i notice that the
I have never worked on jquery but after some googling and learning I have
i never worked with web programming and i've been asked lately to write a
I've never worked with percentage layouts. Of course, I already study them, but without

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.