giozh
giozh

Reputation: 10068

simulate Home button behavior inside an activity

I would like to simulate behavior of soft Home button. I'd like that when user tap back button in a specific Activity of my application, this go in background and show device homepage. How can i do (i know i should override onBackPressed() inside activity )

Upvotes: 1

Views: 1620

Answers (2)

user2323471
user2323471

Reputation: 85

@Override
public void onBackPressed() {
    super.onBackPressed();
    Intent l = new Intent(Friend_list.this, HomeActivity.class);
    startActivity(l);
}

Upvotes: 0

DroidDev
DroidDev

Reputation: 1525

If you know how to override onBackPressed() then override this method and in this method do like:

Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startMain);

Upvotes: 6

Related Questions