Question

I have an Android app with an AlarmManager that repeats every 15 minutes. Depending on the results from this I want to update the UI, but I don't want Android to bring the app to the foreground if it doesn't have focus already.

How can I do this? Alternatively, how can I make the UI updates run in onResume?

I'm calling methods like public static void updateRunningStatusTextView(Boolean inStatus) on the main activity from services and classes

Was it helpful?

Solution

I'm pretty sure your first option can't happen. There is postInvalidate() that can update the View from a non UI thread but this is available

...only when this View is attached to a window.

according to the Docs

Alternatively, how can I make the UI updates run in onResume?

This depends on many things such as the View, the data, and what you have in your code but you could set the data in a static class or save it in something like SharedPreferences then retrieve the data from there, say a String to use in setText() of a TextView

OTHER TIPS

@Override
protected void onRestart() {
    super.onRestart();
    new Handler().postDelayed(new Runnable() {

        public void run() {
            // update UI here from cached values
        }
    }, 100);
}

Well, you don't. If it is in background, you don't need to update the UI!

Then you just need to update the UI when you resume your app (onResume), with the latest data you have.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top