Avinazz
Avinazz

Reputation: 372

How to Update UI when Application is minimized

I want to develop a chat application. In that, when the application is in foreground, everything is working fine. However, when the application is minimized, I want to show notifications to user that new message has arrived. If the user does not respond to that message within 1 minute, the message will be deleted.

So here is what I am doing:

  1. In Service I am listening to new message
  2. When a new message arrives, I start one timer using Runnable
  3. If the time elapses, the message is deleted

All of above works fine when the application is active (meaning in foreground).

But when the application is in background (minimized and new message is coming), the notification is shown and my timer starts, but the UI is not updating.

I tried putting code in runOnUIThread but that didn't work.

Anyone have any ideas on how I can implement this?

Upvotes: 1

Views: 329

Answers (1)

Umesh
Umesh

Reputation: 4256

The problem is that the application is in pause mode when its not on the foreground.

You can however update the UI in the onResume method. Whenever the user reopens the application onResume will be called and the UI will get executed.

Upvotes: 3

Related Questions