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

  • SEARCH
  • Home
  • 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 8846577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:01:21+00:00 2026-06-14T12:01:21+00:00

PROBLEM: The phone/emulator locks up on repeated Notification updates. The only way to get

  • 0

PROBLEM:

The phone/emulator locks up on repeated Notification updates. The only way to get the emulator back responsive after it gets locked is by pressing Home => Menu => Lock => Home => Menu Button in that given order.

CODE:

Notification pushing code:

        // Set up notifcation views
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
        NotificationManager notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); // Get notification manager
        RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.service_notification);
        contentView.setViewVisibility(R.id.current_error_text, View.GONE);
        contentView.setViewVisibility(R.id.error_text, View.GONE);
        contentView.setViewVisibility(R.id.info_error_text, View.GONE);
        contentView.setViewVisibility(R.id.info_text, View.GONE);
        contentView.setViewVisibility(R.id.next_check_in_text, View.VISIBLE);
        contentView.setViewVisibility(R.id.current_profile_text, View.VISIBLE);
        contentView.setViewVisibility(R.id.profile_name_text, View.VISIBLE);
        contentView.setTextViewText(R.id.next_check_in_text, mainText);
        // Set profile text now
        contentView.setTextViewText(R.id.profile_name_text, miniText);
        // Set up a new notification
        Notification notif = new Notification(R.drawable.service_logo_small, "Service is running", System.currentTimeMillis());
        notif.contentView = contentView; // Set content view
        // Create and plug in the PendingIntent
        Intent notifIntent = new Intent(this, EntryPointActivity.class);
        PendingIntent pIntent = PendingIntent.getActivity(this, 0, notifIntent, 0); // Set up the Pending Intent
        notif.contentIntent = pIntent;
        // Now set up notification flags
        notif.flags |= Notification.FLAG_NO_CLEAR;
        notif.flags |= Notification.FLAG_ONGOING_EVENT;
        notif.flags |= Notification.FLAG_FOREGROUND_SERVICE;
        if(sp.getBoolean("UpdateLights", true)) notif.flags |= Notification.DEFAULT_LIGHTS;
        if(sp.getBoolean("UpdateVibrate", true)) notif.flags |= Notification.DEFAULT_VIBRATE;
        if(sp.getBoolean("UpdateSound", true)) notif.flags |= Notification.DEFAULT_SOUND;

        notificationManager.notify(R.string.app_name, notif);

All objects exist and the project compiles perfectly. I encounter NO NullPointerExceptions!

Code calling the notification creating function:

final Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask(){
@Override
public void run() {
    if(( nextUpdateIn - System.currentTimeMillis() ) > 0) {
        long milliseconds = (nextUpdateIn - System.currentTimeMillis());
        int seconds = (int) (milliseconds / 1000) % 60 ;
        int minutes = (int) ((milliseconds / (1000*60)) % 60);
        String toShow = "Next Check In: " + minutes + " minute" + ((minutes != 1) ? "s" : "") + " " + seconds + " second" + ((seconds != 1) ? "s" : "");
        pushNotification(STATE_LOADEDSUCCESSFULLY, currentProfile.getProfileName(), toShow);
    } else {
        currentState = STATE_RELOADING;
        pushNotification(STATE_RELOADING, null, "Refreshing..");
        timer.cancel();
    }
}
}, 1, 999);

Again, all objects exist!
The notification IS UPDATED in the above process but it locks up BOTH THE EMULATOR AND PHONE as mentioned above!

AIM:

To update notification in the Status Bar to basically show a countdown till the next refresh.

EDIT:

I’m trying to run this code via a SERVICE and I’ve tried on emulators running Android 2.2, 2.3.3, 4.1 and all of them give me the same problem!

  • 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-14T12:01:22+00:00Added an answer on June 14, 2026 at 12:01 pm

    Well, I finally figured what the problem is.

    You may be interested in this link too: http://code.google.com/p/android/issues/detail?id=13941#c12

    So, according to the above link, I stopped create a new Notification object everytime the notification pushing function is called. Now, I create the object once and keep reusing it! This has stopped the emulator lock ups!

    Following is the modification to the Notification pushing code:

        // Set up notifcation views
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
        RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.service_notification);
        contentView.setViewVisibility(R.id.current_error_text, View.GONE);
        contentView.setViewVisibility(R.id.error_text, View.GONE);
        contentView.setViewVisibility(R.id.info_error_text, View.GONE);
        contentView.setViewVisibility(R.id.info_text, View.GONE);
        contentView.setViewVisibility(R.id.next_check_in_text, View.VISIBLE);
        contentView.setViewVisibility(R.id.current_profile_text, View.VISIBLE);
        contentView.setViewVisibility(R.id.profile_name_text, View.VISIBLE);
        contentView.setTextViewText(R.id.next_check_in_text, mainText);
        // Set profile text now
        contentView.setTextViewText(R.id.profile_name_text, miniText);
        // Set up a new notification
        notif.contentView = contentView; // Set content view
        // Create and plug in the PendingIntent
        Intent notifIntent = new Intent(this, EntryPointActivity.class);
        PendingIntent pIntent = PendingIntent.getActivity(this, 0, notifIntent, 0); // Set up the Pending Intent
        notif.contentIntent = pIntent;
        // Now set up notification flags
        notif.flags |= Notification.FLAG_NO_CLEAR;
        notif.flags |= Notification.FLAG_ONGOING_EVENT;
        notif.flags |= Notification.FLAG_FOREGROUND_SERVICE;
        if(sp.getBoolean("UpdateLights", true)) notif.flags |= Notification.DEFAULT_LIGHTS;
        if(sp.getBoolean("UpdateVibrate", true)) notif.flags |= Notification.DEFAULT_VIBRATE;
        if(sp.getBoolean("UpdateSound", true)) notif.flags |= Notification.DEFAULT_SOUND;
    
        notificationManager.notify(R.string.app_name, notif);
    

    You’d probably be seeing that the NotificationManager and Notification are no longer being created in the notification pushing code.

    Following are the changes I made to the timer:

    NotificationManager notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); // Get notification manager
    Notification notif = new Notification(R.drawable.service_logo_small, "Service is running", System.currentTimeMillis());
    final Timer timer = new Timer();
    timer.scheduleAtFixedRate(new TimerTask(){
    @Override
    public void run() {
        if(( nextUpdateIn - System.currentTimeMillis() ) > 0) {
            long milliseconds = (nextUpdateIn - System.currentTimeMillis());
            int seconds = (int) (milliseconds / 1000) % 60 ;
            int minutes = (int) ((milliseconds / (1000*60)) % 60);
            String toShow = "Next Check In: " + minutes + " minute" + ((minutes != 1) ? "s" : "") + " " + seconds + " second" + ((seconds != 1) ? "s" : "");
            pushNotification(STATE_LOADEDSUCCESSFULLY, currentProfile.getProfileName(), toShow);
        } else {
            currentState = STATE_RELOADING;
            pushNotification(STATE_RELOADING, null, "Refreshing..");
            timer.cancel();
        }
    }
    }, 1, 999);
    

    As you may be seeing, I reuse the object notificationManager and notif in the timer and thus the CPU is not burdened to re-create the Notification object every time the Timer is being executed.

    So, with the above code changes my code now works perfectly!

    Thanks for helping me.

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

Sidebar

Related Questions

I get a problem about returning phone keypads. For instance, if I input 1-80-0Apple,
I am having a problem with my Windows Phone application. When I get the
I am really struggling to get the Windows Phone 7 emulator connecting to the
I have a worry my long problem, that's my windows phone 7 emulator always
I've got a problem with a binding in my windows phone project. I'm binding
i have a problem with the stopping of a windows phone xna game. i
I have a problem On 3GS Iphone.When i deploying a application on phone then
Problem: Been struggling to get my code to load external shaders and it is
facebook.authorize(this,new String[] { email, read_stream },new DialogListener() giving me problem on mobile phone... but
I have a problem where the spinner I use display correctly in the emulator

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.