Going to the apps screen when pressing the back button in android

Hamreen Ahmad

I have an android app my app needs to go to the Apps screen when i press Back button, So i'am using the following code for that purpose

@Override
public void onBackPressed()
 { 
    Intent i= new Intent(Intent.ACTION_ALL_APPS);
    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    i.addCategory(Intent.CATEGORY_HOME);
    startActivity(i); 
}

But it doesn't work and say "unfortunately Your application has stopped"
who know what is the problem , or provide another way to do same thing

Qasim

You can do this by using below Intent. This intent will start the Launcher app that the user has defined.

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

Or you can also use this one line solution:

moveTaskToBack(true);  // activity.moveTaskToBack(true)

it will behave as Home Button is pressed

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Android: app crashes after going back and pressing a button

From Dev

Going back in Fragments by pressing the back button

From Dev

Android runOnUiThread crash when pressing Back button

From Dev

Avoid splash screen activity when pressing Back button

From Dev

Error when pressing back button

From Java

Why the flash screen in many Android apps is not closed when the back button is clicked?

From Dev

refresh state on going to previous scene in react native from native (android) activity after pressing back button

From Dev

How do I go back to previous screen on pressing back button in Android

From Dev

Android back stack one fragment, when pressing hardware back button shows the back stacked one.

From Dev

going back to the parent activity on pressing app icon button

From Dev

going back to the parent activity on pressing app icon button

From Dev

Pressing home button and going back into the app causes the app to crash

From Dev

Android activity go back to activity that started it instead of parent activity when pressing navigation bar back button

From Dev

App closing when pressing go back button

From Dev

When pressing the back button on the phone, the app minimizes

From Dev

ANDROID: Activity state after pressing the back button

From Dev

Android Gridview is not refreshed while pressing back button

From Dev

Android Gridview is not refreshed while pressing back button

From Dev

Black screen when pressing Home button

From Dev

Black screen when pressing Home button

From Dev

android two dialogs - how to return to the previous one when pressing back button

From Dev

Android Search menu item disappears when pressing back button/collapsing search field

From Dev

pressing a button and going to a previous layout

From Dev

pressing a button and going to a previous layout

From Dev

Fragment pressing back button

From Dev

onActivityResult not called when pressed back arrow on screen but only called when back button pressed in android?

From Dev

Display back button of action bar is not going back in Android

From Dev

GNOME Boxes: VM gets paused when going back to home screen

From Dev

Ajax "POST" is showing form entries in URL when pressing back button

Related Related

  1. 1

    Android: app crashes after going back and pressing a button

  2. 2

    Going back in Fragments by pressing the back button

  3. 3

    Android runOnUiThread crash when pressing Back button

  4. 4

    Avoid splash screen activity when pressing Back button

  5. 5

    Error when pressing back button

  6. 6

    Why the flash screen in many Android apps is not closed when the back button is clicked?

  7. 7

    refresh state on going to previous scene in react native from native (android) activity after pressing back button

  8. 8

    How do I go back to previous screen on pressing back button in Android

  9. 9

    Android back stack one fragment, when pressing hardware back button shows the back stacked one.

  10. 10

    going back to the parent activity on pressing app icon button

  11. 11

    going back to the parent activity on pressing app icon button

  12. 12

    Pressing home button and going back into the app causes the app to crash

  13. 13

    Android activity go back to activity that started it instead of parent activity when pressing navigation bar back button

  14. 14

    App closing when pressing go back button

  15. 15

    When pressing the back button on the phone, the app minimizes

  16. 16

    ANDROID: Activity state after pressing the back button

  17. 17

    Android Gridview is not refreshed while pressing back button

  18. 18

    Android Gridview is not refreshed while pressing back button

  19. 19

    Black screen when pressing Home button

  20. 20

    Black screen when pressing Home button

  21. 21

    android two dialogs - how to return to the previous one when pressing back button

  22. 22

    Android Search menu item disappears when pressing back button/collapsing search field

  23. 23

    pressing a button and going to a previous layout

  24. 24

    pressing a button and going to a previous layout

  25. 25

    Fragment pressing back button

  26. 26

    onActivityResult not called when pressed back arrow on screen but only called when back button pressed in android?

  27. 27

    Display back button of action bar is not going back in Android

  28. 28

    GNOME Boxes: VM gets paused when going back to home screen

  29. 29

    Ajax "POST" is showing form entries in URL when pressing back button

HotTag

Archive