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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:08:42+00:00 2026-06-11T19:08:42+00:00

I am trying to make my program use less resources when I send it

  • 0

I am trying to make my program use less resources when I send it to the background through overriding the onClose() function. My first step is to stop it painting text and gauge fields.

I’ve been reading this doc on Efficiency,
“Eliminating unnecessary processing on the device”

“You can use methods to stop animating or repainting the screen when the screen is not visible, and resume when the screen is visible again. You can override Screen.onExposed(), which is invoked when your application’s screen is on top of the display stack and displayed to the user. You can override Screen.onObscured(), which is invoked when your application’s screen is not displayed to the user or is obscured by another screen.”

I know if I use isForeground(), it will stop it from painting if my app is in the background, but will it do the same if it is obscured by another app? It seems much more simpler to use isForeground()

private boolean isExposed;

protected void onExposed()
{
    isExposed = true;
}
protected void onObscured()
{
    isExposed = false;
}

public void batteryStatusChange(int status) 
{
    // TODO Auto-generated method stub
    if ((status & DeviceInfo.BSTAT_LEVEL_CHANGED) != 0)
    {
//is there a difference between the two if's?

        //if(isExposed)     
        //if(UiApplication.getUiApplication().isForeground())

        {
        batteryStatusField.setText(getBatteryLevel());
        bitGauge6.setValue(DeviceInfo.getBatteryLevel());
        }       


    }
}
    public boolean onClose()
{
    UiApplication.getUiApplication().requestBackground();
    return true;
}
  • 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-11T19:08:44+00:00Added an answer on June 11, 2026 at 7:08 pm

    In general, isForeground() tells you if your app is running in the foreground. However, as you’ve implemented it, the isExposed variable only tells you when the screen that it belongs to has been exposed, or obscured (because you’re setting it in the Screen.onExposed() and Screen.onObscured() methods).

    For your app, maybe you only have one Screen subclass?

    Most apps will have many screens. So, in that situation, the isExposed variable would only be telling you whether or not one (of many) screens is showing.

    If your app only has the single Screen, then either technique should work for you.

    However, as I said in my comment, if the code you’ve posted is showing all that you’re doing in the batteryStatusChange() callback, then I don’t think you really need to worry about performance. It’s good to be considerate of performance on mobile devices, but neither of the UI calls you make in that method should incur any significant performance cost.

        batteryStatusField.setText(getBatteryLevel());
        bitGauge6.setValue(DeviceInfo.getBatteryLevel());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make a program that lets you input any one-step equation, and
I'm trying to make a program to calculate the cos(x) function using taylor series
I'm trying to make a program that will open a directory, then use regular
I am trying to learn to use the wx packages to make GUI programs
Im trying to make a program that retrieves an endless amount of numbers that
I'm trying to make a program that, using pointers, detects lines in an image
I'm trying to make a program which will create a sum of directories the
I'm trying to make a program that can be hosted by many peoples, like
I am trying to make a program that can take an .mp3 file from
I am trying to make a program that automatically corrects the perspective of a

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.