Andro id
Andro id

Reputation: 31

How to force my application move to the foreground?

I wrote an application which has a flow in which there is a waiting for some server event to happen (waiting by polling till desired resault returned). it is natural that the wait time will be minutes. I would like that the application users will be able to run other applicatins, but once my applications thread got the desired server response, I want my application to return to the foreground.

How do I return my application to the forground (from a thread that my application created)?

I tried the common way of runOnUiThread, but it didn't work while my application is not on the foreground.

thanks.

Upvotes: 2

Views: 7718

Answers (2)

Teasel
Teasel

Reputation: 960

In the spirit of answering the question posed... see this post for ways that you might achieve this.

However, just because you can doesn't mean you should! Your users may have thought they'd be willing to go immediately back into your app, when they started the async task, but that was before their friend got run over by a bus, and they now want to use the phone to call an ambulance...

So, no, it should absolutely not popup and take over. It should display a notification to the user, who will click on it when they're good and ready. As the android docs themselves say: "A background service should never launch an activity on its own in order to receive user interaction." (emphasis theirs!)

Upvotes: 1

H9kDroid
H9kDroid

Reputation: 1824

It's a bad thing to force your application upon users, perhaps they are doing smth more important?

The way to solve this is to use a notification, then your users will be notified that new data have arrived, and can select to open your application if and when they got the time.

Upvotes: 6

Related Questions