How to bring an application forward(from the background to foreground)?

Asked

Viewed 137 times

0

I’m finishing an app where the person runs it but usually it is minimized, running in the background.

The person executes it, but a lot of the time the person can be playing with other things on the phone.

I would like this app, responding to a particular event (a response from a webservice, for example), to reappear for the user, even if this user is working on other apps.

We can say that this application at certain times has top priority and needs to be displayed to the user, interrupting any action he is doing.

1 answer

1


The mechanism used on Android to indicate to the user that an application needs their attention are the notifications.

The application launches the notification, the user when he understands reads the message and acts accordingly. This is the advised form, because it is not invasive.

If you really want to bring your Activity forward without the user’s consent, use the startActivity().

Intent it = new Intent(this, MyActivity.class);
it.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(it);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.