Académique Documents
Professionnel Documents
Culture Documents
Stack Overflow
log in
49
homescreen
I want to go to the home screen programmatically in Android when the user clicks on button. How can this be done?
share
Asked
Sep 16 '10 at 7:22
Jonik
34.5k 40 170 231
11
Edited
Dec 20 '13 at 18:59
please, accept some of your older questions. Yossarian Sep 16 '10 at 7:25
A simple way is to override onBackPressed or through keyEvent =Backpressed and call onHomePressed on it. then it will behave like homePressed Nepster May 29 '14 at 13:27
add a comment
4 Answers
94
Order By
Votes
This Intent will start the launcher application that the user has defined. Be careful with this because this will look like your application crashed
share
Answered
Sep 16 '10 at 8:41
Edited
Oct 15 '14 at 7:25
I've read that this is very wrong to do in an App. But why do people say it? I know where I'm using it. And it looks like that's the only thing I can do to do what I want to do. So is this
ok to use it? Enigma Nov 19 '12 at 7:05
Simplest thing that works for me: startActivity(new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME)); (FLAG_ACTIVITY_NEW_TASK doesn't seem to
be necessary.) Jonik Dec 20 '13 at 18:58
This is an older thread, but although this works returning back to the previous Activity does not work. What attributes to that? portfoliobuilder Sep 25 '14 at 18:49
@portfoliobuilder, you just need to remove FLAG_ACTIVITY_NEW_TASK. user802421 Oct 30 '15 at 6:46
what does ACTION_MAIN and CATAGORY_HOME refer to? Srujan Barai Jan 1 at 11:50
add a comment
Now you can send the user to the device home screen from any class in your app, not just Activities, Fragments, or other Classes with a
reference to the current Activity (you can decide whether this is a good or bad thing):
Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
YourApplication.getContext().startActivity(startMain);
share
Answered
Mar 15 '12 at 19:50
Edited
Oct 15 '14 at 7:27
share
Answered
Aug 7 '15 at 7:42
It's working.. Is it a good approach.. Will it work in every case? Prabs Nov 20 '15 at 5:52
In my situation it works fine.I am not quiet sure whether it works in all cases or not Nepster Nov 26 '15 at 7:55
add a comment
share
stOle there is nothing wrong with asking questions that can be answered with a quick google query and a look into the documentation. If the question contains the correct keywords
it will show up on the first google page very quickly and makes finding the correct information and sample code much much faster then to look into the documentation. I'm a
somehow trained android programmer but I would have to google and to skip over one or two pages to answer this question. It would be great if the answer to this question is here
where it can be edited, improved, updated and rated. Janusz Sep 16 '10 at 8:37
@Janusz, I didn't mean to sound harsh... st0le Sep 16 '10 at 8:54
add a comment
Your Answer
log in
or
Name
By posting your answer, you agree to the privacy policy and terms of service.
meta chat tour help blog privacy policy legal contact us full site
Download the Stack Exchange Android app
2016 Stack Exchange, Inc