Thursday, December 24, 2015

Android bringing Activity to foreground

To bring activity to the foreground, Below simple code can be done. 

Intent notificationIntent = new Intent(this, MainActivity.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
try
{
    pendingIntent.send();
}
catch (CanceledException e)
{
    e.printStackTrace();

}

References:
http://stackoverflow.com/questions/12074980/bring-application-to-front-after-user-clicks-on-home-button

No comments:

Post a Comment