androidandroid-activityforegroundandroid-homebutton

How to bring activity to front after "home" button has been pressed


I've been reading lots of post but no luck. What I want is a similar behaviour to NoLed application, when the screen turns off i want to reenable it and show a low consumption screen. If the screen turs off when my aplication is in the foreground (visible to the user) everything goes OK, but if I press the home button and lock the phone or wait till the screen turns off, my low consumption screen won't be visible and the behaviour won't be the spected one. I've trying with this code, and all the possible flags mixed, alone... but no luck:

Intent i=new Intent(Este,BajoConsumo.class);
i.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
//i.addFlags(...);
startActivity(i);

Solution

  • After some research I have found that the way to do this is to call;

    Intent i=new Intent(this, BajoConsumo.class);
    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(i);
    

    from a service, that will open and focus the new activity, and it will become visible.