How to exit current activity to homescreen (without using "Home" button)?

Posted by steff on Stack Overflow See other posts from Stack Overflow or by steff
Published on 2010-05-03T14:36:34Z Indexed on 2010/05/30 14:52 UTC
Read the original article Hit count: 292

Filed under:
|
|
|

Hi everyone,

I am sure this will have been answered but I proved unable to find it. So please excuse my redundancy.

What I am trying to do is emulating the "Home" button which takes one back to Android's homescreen. So here is what causes me problems:

  • I have 3 launcher activities. The first one (which is connected to the homescreen icon) is just a (password protected) configuration activity. It will not be used by the user (just admin)
  • One of the other 2 (both accessed via an app widget) is a questionnaire app. I'm allowing to jump back between questions via the Back button or a GUI back button as well. When the questionnaire is finished I sum up the answers given and provide a "Finish" button which should take the user back to the home screen.

For the questionnaire app I use a single activity (called ItemActivity) which calls itself (is that recursion as well when using intents?) to jump from one question to another:

Questionnaire.serializeToXML();  
Intent i = new Intent().setClass(c, ItemActivity.class);  
if(Questionnaire.instance.getCurrentItemNo() == Questionnaire.instance.getAmountOfItems()) {  
    Questionnaire.instance.setCompleted(true);  
} else Questionnaire.instance.nextItem();  
startActivity(i);

The final screen shows something like "Thank you for participating" as well as the formerly described button which should take one back to the homescreen. But I don't really get how to exit the Activity properly. I've e.g. used this.finish(); but this strangely brings up the "Thank you" screen again. So how can I just exit by jumping back to the homescreen??

Sorry for the inconvinience.
Regards,
Steff

© Stack Overflow or respective owner

Related posts about android

Related posts about activity