skip one activity on back

Put your problem here if it does not fit any of the other categories.

skip one activity on back

Postby xalien » Fri Feb 11, 2011 3:57 pm

hi all, it's possible, when I use back command, to skip one activity. This is an example of what I want:
Normal application flow:
Activity1 -> Activity2 -> Activity3
back, back, ...
Activity1 <-------------- Activity3 <- ....
thanks
xalien
Freshman
Freshman
 
Posts: 3
Joined: Fri Feb 11, 2011 9:49 am

Top

Re: skip one activity on back

Postby urbantrad » Wed Feb 16, 2011 10:39 pm

There are a few options i can think of straight away, depending on what effect exactly you want.
You could, after sending the intent for Activity3, make Activity2 stop itself.
You could implement the onActivityResult (not sure about the name, something like that) method, and perform actions you want (like closing the activity) when returning from another activity.
urbantrad
Senior Developer
Senior Developer
 
Posts: 104
Joined: Thu Sep 09, 2010 10:19 pm

Re: skip one activity on back

Postby strider2023 » Mon Feb 28, 2011 1:21 pm

Well one simple method would be overriding the back button like the following:

Activity 3
Code: Select all
@Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
              Intent HomePageIntent = new Intent(Activity3.this,Activity1.class);
         startActivity(HomePageIntent);
        }
        return super.onKeyDown(keyCode, event);
    }
strider2023
Senior Developer
Senior Developer
 
Posts: 126
Joined: Tue Mar 02, 2010 6:34 am
Location: Chennai, India

Re: skip one activity on back

Postby blundell » Mon Feb 28, 2011 9:40 pm

Worst idea is over riding the back button. This means you will completely mess up the 'Activity Stack' when you come to use the back button on other screens.

Just override the onResume of the Activity you want to skip, have a global variable in a class that extends Application. When Activity 3 is finished (i.e. in it's onPause, set the global var to true); Then in activity 2's onResume just check for that global var and if == true finish();
http://developer.android.com/reference/android/app/Activity.html#ActivityLifecycle
http://stackoverflow.com/questions/708012/android-how-to-declare-global-variables
User avatar
blundell
Master Developer
Master Developer
 
Posts: 1610
Joined: Tue Nov 18, 2008 12:58 pm
Location: UK

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 24 guests